Giter Site home page Giter Site logo

burhanrashid52 / photoeditor Goto Github PK

View Code? Open in Web Editor NEW
4.0K 108.0 976.0 21.3 MB

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.

License: MIT License

Kotlin 100.00%
android image-processing photo-editor emoji paint stickers text-editor instagram facebook stories

photoeditor's Introduction

PhotoEditor

Github Action Downloads API JavaDoc Uplabs AndroidArsenal AndroidDevDigest AwesomeAndroid AndroidWeekly Mindorks

A Photo Editor library with simple, easy support for image editing using Paints, Text, Filters, Emoji and Sticker like stories.

Download link

PhotoEditor - Android SDK with simple, easy support for image editing. | Product Hunt

Buy Me A Coffee

Features

Benefits

  • Hassle free coding
  • Increase efficiency
  • Easy image editing

Getting Started

To start with this, we need to simply add the dependencies from mavenCentral() in the gradle file of our app module like this

implementation 'com.burhanrashid52:photoeditor:3.0.2'

or we can also import the :photoeditor module from sample for further customization

Migrations

AndroidX

PhotoEditor v.1.0.0 is a migration to androidX and dropping the support of older support library. There are no API changes. If you find any issue migrating to v.1.0.0 , please follow this Guide. If you still facing the issue than you can always rollback to v.0.4.0. Any fix in PR are Welcome :)

Kotlin

PhotoEditor v.2.0.0 is fully migrated to Kotlin. You can use v.1.5.1 for the Java version. There are no breaking API changes in these two versions.

Setting up the View

First we need to add PhotoEditorView in our xml layout

 <ja.burhanrashid52.photoeditor.PhotoEditorView
        android:id="@+id/photoEditorView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:photo_src="@drawable/got_s" />
  

We can define our drawable or color resource directly using app:photo_src

We can set the image programmatically by getting source from PhotoEditorView which will return a ImageView so that we can load image from resources,file or (Picasso/Glide)

PhotoEditorView mPhotoEditorView = findViewById(R.id.photoEditorView);

mPhotoEditorView.getSource().setImageResource(R.drawable.got);

Building a PhotoEditor

To use the image editing feature we need to build a PhotoEditor which requires a Context and PhotoEditorView which we have to setup in our xml layout

//Use custom font using latest support library
Typeface mTextRobotoTf = ResourcesCompat.getFont(this, R.font.roboto_medium);

//loading font from asset
Typeface mEmojiTypeFace = Typeface.createFromAsset(getAssets(), "emojione-android.ttf");

mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
         .setPinchTextScalable(true)
         .setClipSourceImage(true)
         .setDefaultTextTypeface(mTextRobotoTf)
         .setDefaultEmojiTypeface(mEmojiTypeFace)
         .build();

We can customize the properties in the PhotoEditor as per our requirement

Property Usage
setPinchTextScalable() set false to disable pinch to zoom on text insertion. Default: true.
setClipSourceImage() set true to clip the drawing brush to the source image. Default: false.
setDefaultTextTypeface() set default text font to be added on image
setDefaultEmojiTypeface() set default font specifc to add emojis

That's it we are done with setting up our library

Drawing

We can customize our brush and paint with different set of property. To start drawing on image we need to enable the drawing mode

Type Method
Enable/Disable mPhotoEditor.setBrushDrawingMode(true);
Shape (brush, line, oval, rectangle, arrow) mPhotoEditor.addShape(shape)
Shape size (px) mPhotoEditor.setBrushSize(brushSize) or through the a ShapeBuilder
Shape opacity (In %) mPhotoEditor.setOpacity(opacity) or through the a ShapeBuilder
Shape color mPhotoEditor.setBrushColor(colorCode) or through the a ShapeBuilder
Brush Eraser mPhotoEditor.brushEraser()

Note: Whenever we set any property of a brush for drawing it will automatically enable the drawing mode

Shapes

We can draw shapes from v.1.5.0. We use ShapeBuilder to define shape and other properties.

val shapeBuilder = ShapeBuilder()
    .withShapeOpacity(100)
    .withShapeType(ShapeType.Oval)
    .withShapeSize(50f);

photoEditor.setShape(mShapeBuilder)

For more details check ShapeBuilder.

Filter Effect

We can apply inbuild filter to the source images using

mPhotoEditor.setFilterEffect(PhotoFilter.BRIGHTNESS);

We can also apply custom effect using Custom.Builder

For more details check Custom Filters

Text

We can add the text with inputText and colorCode like this

mPhotoEditor.addText(inputText, colorCode);

It will take default fonts provided in the builder. If we want different fonts for different text we can set typeface with each text like this

mPhotoEditor.addText(mTypeface,inputText, colorCode);

In order to edit the text we need the view, which we will receive in our PhotoEditor callback. This callback will trigger when we Long Press the added text

mPhotoEditor.setOnPhotoEditorListener(new OnPhotoEditorListener() {
           @Override
           public void onEditTextChangeListener(View rootView, String text, int colorCode) {
               
           }
       });

Now we can edit the text with a view like this

mPhotoEditor.editText(rootView, inputText, colorCode);

If you want more customization on text. Please refer the wiki page for more details.

Emoji

We can add the Emoji by PhotoEditor.getEmojis(getActivity()); which will return a list of emojis unicode.

mPhotoEditor.addEmoji(emojiUnicode);

It will take default fonts provided in the builder. If we want different Emoji fonts for different emoji we can set typeface with each Emoji like this

mPhotoEditor.addEmoji(mEmojiTypeface,emojiUnicode);

Adding Images/Stickers

We need to provide a Bitmap to add our Images mPhotoEditor.addImage(bitmap);

Undo and Redo

  mPhotoEditor.undo();
  mPhotoEditor.redo();

Deleting

For deleting a Text/Emoji/Image we can click on the view to toggle the view highlighter box which will have a close icon. So, by clicking on the icon we can delete the view.

Saving

In v.3.0.0 onward, we can save an image to a file using coroutines:

// Please note that if you call this from a fragment, you should call
// 'viewLifecycleOwner.lifecycleScope.launch' instead.
lifecycleScope.launch {
    val result = photoEditor.saveAsFile(filePath)
    if (result is SaveFileResult.Success) {
        showSnackbar("Image saved!")
    } else {
        showSnackbar("Couldn't save image")
    }
}

You can also save an image to a file from Java. We need to provide a file with callback method when edited image is saved.

 mPhotoEditor.saveAsFile(filePath, new PhotoEditor.OnSaveListener() {
                 @Override
                 public void onSuccess(@NonNull String imagePath) {
                    Log.e("PhotoEditor","Image Saved Successfully");
                 }

                 @Override
                 public void onFailure(@NonNull Exception exception) {
                     Log.e("PhotoEditor","Failed to save Image");
                 }
             });

For more details see Saving

How to contribute?

Questions?🤔

Hit me on twitter Twitter Medium Facebook

FAQ

Can I use this library in my app for free?

Yes. It's an open-source library and free to use. If this library has saved your time then showing a little credit will increase my motivation towards making the library better :)

Does it support the CROP feature?

Currently, No. I started to build in branch PE-79. But due to time constraint, I drop the idea. Any PR related to CROP is welcomed :)

Facing issues in applying Filter?

The filter effect is applied using GlSurfaceView and the implementation of this feature causing a lot of issues. Need to think of some other alternative solution. Here is the issue list.

Does is support in other platforms (iOS, Web, Flutter)?

No. Currently, the focus is on making the android library better. We don't have any plans for other Platform.

Other Know Issues

Image Scaling.
Memory Issue in Filter.

Who is using PhotoEditor?

  1. Pixxo
  2. Couple Blog: Long distance
  3. Screenshot Tile (NoRoot)

Note: I will be happy to add your app to the list. Please reach out to me with details. You know how to reach me :)

Credits

This project is inspired from PhotoEditorSDK

Buy a cup of coffee

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of ☕️ BuyMeACoffee

PhotoEditor - Android SDK with simple, easy support for image editing. | Product Hunt

Lesson Learned from building successful android library PhotoEditor: Droidcon Berlin 2021

Lesson Learned from building successful android library PhotoEditor

MIT License

Copyright (c) 2022 Burhanuddin Rashid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

photoeditor's People

Contributors

anderbytes avatar ankitivo avatar burhanrashid52 avatar chrsngular avatar cvzi avatar datl4g avatar ftahery avatar gabrielnakhata avatar hooyee-dji avatar jspiner avatar kevinminions avatar licaon-kter avatar longdt57 avatar lucianocheng avatar maciej-klupp avatar perezfer avatar rtz333 avatar s4cha avatar sagarkondhare avatar samanfekri avatar shadjac avatar stephanepechard avatar tanodxyz avatar tiendung717 avatar unbiaseduser avatar vardantitan avatar wasky avatar yumin2019 avatar zerezhka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

photoeditor's Issues

How can I make it work in landscape view?

Hi,

I'm making an app for tablet and need it to work in landscape view, but at the moment it doesn't work.
When I click on "stickers" 'for exemple) I can't see it (but i can when I turn it to portrait).
How can I manage that?
Thanx

Save full resolution

Hi,
Can i save image with original size? As an example, the camera takes pictures at a resolution of 3264x2448. After editing the image, it is saved is the same as when the screen resolution.

I'm used load photo to editor:

void loadPhotoEditor(String filePath) {
        mPhotoEditor.clearAllViews();
        Bitmap photo = BitmapFactory.decodeFile(filePath );
        photoEditorView.getSource().setImageBitmap(photo);  
 }

and save function

@SuppressLint("MissingPermission")
    @OnClick(R.id.btnSave)
    public void onbtnEditSaveClicked() {
        progress = ProgressDialog.show(this, "İşleminiz Yapılıyor....",
                "Görsel kayıt ediliyor", true);
        mPhotoEditor.saveImage(mCurrentPhotoPath, new PhotoEditor.OnSaveListener() {
            @Override
            public void onSuccess(@NonNull String imagePath) {
                if (progress != null) {
                    progress.dismiss();
                }
                Toast.makeText(InspectionDetail_PhotoActivity.this,
                        "Değişiklikler kayıt edildi.", Toast.LENGTH_SHORT).show();
                editMode(false);
                fileAdapter.notifyDataSetChanged();
            } 
            @Override
            public void onFailure(@NonNull Exception exception) {
                if (progress != null) {
                    progress.dismiss();
                }
                Toast.makeText(InspectionDetail_PhotoActivity.this,
                        "Değişiklikler kayıt edilemedi: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
                editMode(false);
            }
        });
    }

New icon / logo

Hi, I am a graphic designer, I want to help others in graphic design.

After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

App crashes on Jelly Bean 4.2.2

Hello there,
App crashes when i open ImageEditorActivity
Here is logcat error.... its related to font
Caused by: java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.(Typeface.java:175)
at android.graphics.Typeface.createFromAsset(Typeface.java:149)
at com.enthuons.photoeditor.EditGalleryImageActivity.onCreate(EditGalleryImageActivity.java:144)

Can you please look into the issue.... On other versions i am not facing this issue but on JB 4.2.2 app get crashed

How to avoid emoji view going outside PhotoEditorView

Hello there,
Suppose i have added emoji on PhotoEditor and try to re position the emoji. The emoji goes outside the PhotoEditorView when i try to move image to extreme Left or Right edges, but if i try to re position emoji extreme Up or Down edges and if some part of Emoji is going outside the PhotoeditorView the emoji is automatically re positioned to center and I want to achieve same result when user try to reposition emoji to Left or Right and some part of emoji is going outside PhotoEditorView.....
Please help me to resolve this issue...
Thanx in advance

Image saving with borders

when i save image if image height is low than auto black border is added into it and if width is low then auto black border is added .

can you please help me ?

Image not saving

Great work! Very useful.

I have cloned the repository and ran the sample app. Image is not saving even on pressing the save button.

If I capture the image, choose the image from the gallery or use the default image for the PhotoEditorView , save option doesn't works.

mProgressDialog is not removing. I checked the image and found the file is created with name 1527754743495.png but no output is written in it.

I tried rebooting the phone but not working.

Here are the logs:

Device: Nexus 5x
OS version: 8.1.0

05-31 13:49:03.497 8982-8982/com.burhanrashid52.imageeditor D/PhotoEditor: Image Path: /storage/emulated/0/1527754743495.png
05-31 13:49:03.618 8982-8989/com.burhanrashid52.imageeditor I/zygote64: Do partial code cache collection, code=47KB, data=58KB
    After code cache collection, code=47KB, data=58KB
    Increasing code cache capacity to 256KB
    Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
05-31 13:49:03.818 8982-8989/com.burhanrashid52.imageeditor I/zygote64: Compiler allocated 7MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
05-31 13:49:03.838 8982-8989/com.burhanrashid52.imageeditor I/zygote64: Do full code cache collection, code=124KB, data=79KB
05-31 13:49:03.839 8982-8989/com.burhanrashid52.imageeditor I/zygote64: After code cache collection, code=78KB, data=39KB

Brush doesn't work on api 17

Min api level for this library is 14 but when I use it on a phone with api level 17 brush draw immediately disappear after touch up.

Sticker

I want to apply some effects on sticker
How to Apply effects on Sticker after view is added how to find which view is currently selected or clicked

Memory issue

screenshot 24

if i change filter multiples time without "largerHeap="true" application crashes and as u can see in screenshot that it take upto 1.2Gb no phone, it some kind of memory leak or something.

How to add frames

Hello sir, I want to add some frame and bellow the frame add images from gallery or camera.

How to Add his features.

Please Help me.

Thanks you

Help needed

Q1. can i use your code in my project
yes/no

Q2. if (Q1.yes) can u help me how i can use this code in my project
yes/no

Q3. do i need
capture
add "photoeditor" with "app" to use in my project

Save problem with image scaling

In my case, the PhotoEditorView fits the whole screen, so if I save the image, it will be exactly the size of my screen, and the actual image is only a small part of that image.

Problem while getting the Adobe Creative API for release

Hi,

This app is made of the highest quality and I want to customize it and publish on Google Play.

One problem that I am facing is that I am not able to generate the key for production from the Adobe Creative Cloud.

It is asking which Creative Component is used in the app.

Can you please list the procedure for creating the key so that we can publish?

Problem with image scaling

I came across two problems while working with the library:

  1. If the image is bigger than the max OpenGL texture size(which is different depending on the device), the image won't be shown. I had this problem before when trying to display a large image in an ImageView. This is less a problem with the library but with Android itself, but nonetheless the library could handle that. My solution was to simply scale the image down to 2048px, this should work on most devices.
public static Bitmap transformBitmapTo2048px(Bitmap source){
        if(source.getHeight() <= 2048 && source.getWidth() <= 2048)
            return source;

        int targetWidth;
        int targetHeight;

        double aspectRatio = (double) source.getHeight() / (double) source.getWidth();

        if(source.getWidth() >= source.getHeight()){
            targetWidth = 2048;
            targetHeight = (int)(2048 * aspectRatio);
        } else {
            targetHeight = 2048;
            targetWidth = (int)(2048 / aspectRatio);
        }

        Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
        if (result != source) {
            // Same bitmap is returned if sizes are the same
            source.recycle();
        }
        return result;
}
  1. The current implementation for editing an image works basically by doing the image processing on the screen and the taking the contents of that to save the image. The problem with that is that the image get scaled down, possibly a lot. For example, if you have a picture in landscape, it will be scaled down quite a lot to fit into the ImageView. In my case, the PhotoEditorView fits the whole screen, so if I save the image, it will be exactly the size of my screen, and the actual (landscape) image is only a small part of that image.
    The correct approach would be to have an internal representation of the image and do all the processing on that. This would allow to keep the original size of the image (you can still show the image scaled down to fix problem 1).

FrameLayout background invisible

Hello!

I would like to make the frameLyout of the imgPhotoEditorImage invisible, and not only when I click on the image, but for exemple if I click on a button "OK".
I can make it work one time but that's it.
Any idea how I can make it work everytime?
Thank you.

Cannot resolve symbol 'font'

Hi! I'm at the beginning of the project, trying to build a photo Editor, so I wrote this code:

//Use custom font using latest support library
Typeface mTextRobotoTf = ResourcesCompat.getFont(this, R.font.roboto_medium);

//loading font from assest
Typeface mEmojiTypeFace = Typeface.createFromAsset(getAssets(), "emojione-android.ttf");

mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
.setPinchTextScalable(true)
.setDefaultTextTypeface(mTextRobotoTf)
.setDefaultEmojiTypeface(mEmojiTypeFace)
.build();

But the "font" in , R.font.roboto_medium stays red and it says "Cannot resolve symbol 'font'

(I have add the dependencies in gradle file and sync it)

Thank you!

Brush color changes after saving image...

Hello there...
I found one bug when using brush....
Suppose i draw something on view in one color and again i draw something using brush in other color (overlapping first one), when we save image brush color automatically changes.
Please refer following screenshots.
Before saving....
img_20180612_114927
After saving image(red color automatically changes to navy blue)
img_20180612_114901
Please check this bug.....

Camera access problem!

when i open camera its always crash the app ? i search everything but nothing found anything can you please help ? i am testing on API 26

Saving the Image

Hi...Very usefull library.while saving the image the progress dialog appears and doesnt desappear anymore .it just remain turning.so i cant save the image..what to do for this?

How to change text cursor position

After i add text and try to edit it by long click, the cursor on text is positioned to starting instead of this it should be positioned to the end of text. please solve this issue

How to get removed ViewType in onRemoveViewListener()

Hello there,
We can determine which view is added on the paretView in onAddViewListener(ViewType viewType, int numberOfAddedViews) in same way i want to know which view is removed in onRemoveViewListener().
Please help me to solve this.

After drawing something, the previous actions are not reversible any more

For example, if I add text, then stickers, emojis, then I can select text again and modify it. Also "undo" works fine.
But if I draw something, then I cannot select any more the text box. Also "undo" does not work any more.
I suppose that prior to drawing, all actions are actually applied to the image. A solution could be to keep all drawing in a separate layer. I also think that in order to simplify things, erase could be applied only to drawing layer .

Transparent image background

How can i have transparent background for image? right now i load the image and save it, but there is some black color around my image. i want it to be only my image and nothing more around it.

Image on photoeditorview is lost in split-screen mode

Hello there,
Suppose i added image from gallery and start app in split-screen mode (multi-window mode). when app enters in split screen mode image on mPhotoEditorView is lost... just black screen is showing.
I face this issue on Android Oreo 8.0
Please test from your side and help me to solve this issue....

Add possibility to disable clearAllViews onSave

I have a process with a few steps of uploading image. First step is photo edit using this library and the second step is adding name of image. After saving photo all stickers disappear in scenario if I want to go back from screen where I'm adding name of an image. Is there possibility to add some flag should photoEditor should clear views or not on save?

Logo design contribution

Hallo
I am Masud Rana
Want to creat a logo for this projects.If you have any requirements then let me know.Its free for any open source projects.

Image is not saving on some devices

Image is not saving properly in some devices i test , response is too late for example 20-30minutes after saving image show in folder . can you suggest me why this is happening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.