Skip to content

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

Notifications You must be signed in to change notification settings

Erraoudy/PhotoEditor

 
 

Repository files navigation

PhotoEditor

Downloads API JavaDoc Uplabs AndroidArsenal AndroidDevDigest AwesomeAndroid

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

Features

  • Drawing on image with option to change its Brush's Color,Size,Opacity and Erasing.
  • 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

Change Logs

  • 0.1.1 : Changed app:src="@drawable/got_s" to app:photo_src="@drawable/got_s" in PhotoEditorView

Getting Started

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

implementation 'ja.burhanrashid52:photoeditor:0.1.1'

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

Setting up the View

First you need to add PhotoEditorView in your 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" />
  

Your can define your drawable or color resource directly using app:photo_src

Your can set the image programatically by getting source from PhotoEditorView which will return a ImageView so that you 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 you need to build a PhotoEditor which requires a Context and PhotoEditorView which we have 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();

You can customize the properties in the PhotoEditor as per your requirement

Property Usage
setPinchTextScalable() set false to disable pinch to zoom on text insertion.By deafult 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 diffrent 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 you set any property for brush for drawing it will automatically enables the drawing mode

Text

You can add the text with input text and colorCode like this

mPhotoEditor.addText(inputText, colorCode);

It will take default fonts provided in the builder,If you want diffrent fonts for diffrent text you can set typeface with each text like this

mPhotoEditor.addText(mTypeface,inputText, colorCode);

In order to edit the text you need the view which you will reacive in you PhotoEditor callback.This callback will trigger when you Long Press the added text

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

Now you can edit the text with a view like this

mPhotoEditor.editText(rootView, inputText, colorCode);

Emoji

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

mPhotoEditor.addEmoji(emojiUnicode);

It will take default fonts provided in the builder,If you want diffrent Emoji fonts for diffrent emoji you can set typeface with each Emoji like this

mPhotoEditor.addEmoji(mEmojiTypeface,emojiUnicode);

Adding Images/Stickers

You need to provide a Bitmap to add you Images mPhotoEditor.addImage(bitmap);

Undo and Redo

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

Deleting

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

Saving

You need provide a file with callback method when edited image is saved

 mPhotoEditor.saveImage(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");
                 }
             });

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

License

Copyright 2018 Burhanuddin Rashid

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%