khnwr / PhotoEditor

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PhotoEditor

CircleCI 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.

Features

  • Drawing on image with option to change its Brush's Color, Size, Opacity and Erasing.
  • Apply Filter Effect on image using MediaEffect
  • Adding/Editing Text with option to change its Color with Custom Fonts.
  • Adding Emoji with Custom Emoji Fonts.
  • Adding Images/Stickers
  • Pinch to Scale and Rotate views.
  • Undo and Redo for Brush and Views.
  • Deleting Views
  • Saving Photo after editing.

Benefits

  • Hassle free coding
  • Increase efficiency
  • Easy image editing

Getting Started

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

implementation 'ja.burhanrashid52:photoeditor:0.4.0'

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

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 assest
Typeface mEmojiTypeFace = Typeface.createFromAsset(getAssets(), "emojione-android.ttf");

mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
         .setPinchTextScalable(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.By default its true
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);
Bursh Size (px) mPhotoEditor.setBrushSize(brushSize)
Color Opacity (In %) mPhotoEditor.setOpacity(opacity)
Brush Color mPhotoEditor.setBrushColor(colorCode)
Brush Eraser mPhotoEditor.brushEraser()

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

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

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 detail check Saving

How to contribute?

What's next?

  • Croping Image with Custom Aspect ratio and more customization text/emoji/stickers

Questions?🤔

Hit me on twitter Twitter Medium Facebook

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 ☕️ PayPal

MIT License

Copyright (c) 2018 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.

About

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

License:MIT License


Languages

Language:Java 100.0%