https://github.com/guhungry/android-photo-manipulator
Android React Native Image Processing API to edit photo programmatically. It features print text, overlay on another image (add watermark), resize, crop, flip, rotate and optimize image size then convert file format to jpeg or png
https://github.com/guhungry/android-photo-manipulator
android image-manipulation image-processing kotlin
Last synced: 5 months ago
JSON representation
Android React Native Image Processing API to edit photo programmatically. It features print text, overlay on another image (add watermark), resize, crop, flip, rotate and optimize image size then convert file format to jpeg or png
- Host: GitHub
- URL: https://github.com/guhungry/android-photo-manipulator
- Owner: guhungry
- License: mit
- Created: 2019-03-13T09:33:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2026-01-13T00:22:49.000Z (5 months ago)
- Last Synced: 2026-01-13T00:40:17.560Z (5 months ago)
- Topics: android, image-manipulation, image-processing, kotlin
- Language: Kotlin
- Homepage:
- Size: 649 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Android Photo Manipulator
[](https://github.com/guhungry/android-photo-manipulator/actions/workflows/build-and-test.yml)
[](https://sonarcloud.io/dashboard?id=guhungry_android-photo-manipulator)
[](https://codecov.io/gh/guhungry/android-photo-manipulator)
[](https://maven-badges.herokuapp.com/maven-central/com.guhungry.android/photo-manipulator)
Android Image Processing API to edit photo programmatically.
This library is used by [react-native-photo-manipulator](https://github.com/guhungry/react-native-photo-manipulator/).
## Installation
Add dependency in module `build.gradle`
```gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'com.guhungry.android:photo-manipulator:1.0.2'
}
```
## Usage BitmapUtils
Import using
`import com.guhungry.photomanipulator.BitmapUtils`
### BitmapUtils.readImageDimensions()
Get width and height of image in `CGSize`
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------|
| image | Bitmap | Yes | Source image |
### BitmapUtils.crop()
Crop image from specified `cropRegion`
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-----------------------------------------------------------|
| image | Bitmap | Yes | Source image to be crop and resize |
| cropRegion | CGRect | Yes | Region to be crop in CGRect(`x`, `y`, `size`, `width`) |
| outOptions | BitmapFactory.Options | Yes | Configuration for decode and encode result bitmap |
### BitmapUtils.cropAndResize()
Crop and resize image from specified `cropRegion` into `targetSize` using resize mode `cover`
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------------------------------------------|
| image | Bitmap | Yes | Source image to be crop and resize |
| cropRegion | CGRect | Yes | Region to be crop in CGRect(`x`, `y`, `size`, `width`) |
| targetSize | CGSize | Yes | Size of result image |
| outOptions | BitmapFactory.Options | Yes | Configuration for decode and encode result bitmap |
| matrix | Matrix | No | Orientation transform matrix from [getCorrectOrientationMatrix()](#bitmaputilsgetcorrectorientationmatrix) |
### BitmapUtils.printText()
Print text into image
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------|
| image | Bitmap | Yes | Source image to be crop and resize |
| text | String | Yes | Text to print in image |
| position | PointF | Yes | Position to in in `x`, `y` |
| color | Int | Yes | Text color |
| textSize | Float | Yes | Text size |
| font | Typeface | No | Font use to print. Default = App's Default Font |
| alignment | Paint.Align | No | Text alignment (`left`, `right` and `center`). Default = `left` |
| thickness | Float | No | Outline of text. Default = 0 |
| rotation | Float | No | Rotation angle in degrees. Default = 0 |
### BitmapUtils.overlayImage()
Overlay image on top of background image
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------|
| background | Bitmap | Yes | Background image |
| overlay | Bitmap | Yes | Overlay image |
| position | PointF | Yes | Position of overlay image in background image |
### BitmapUtils.flip()
Flip the image horizontally, vertically or both
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------|
| image | Bitmap | Yes | The image to be flipped |
| mode | FlipMode | Yes | Flip mode .Horizontal, .Vertical or .Both |
### BitmapUtils.rotate()
Rotate the image 90°, 180° or 270°
| NAME | TYPE | REQUIRED | DESCRIPTION |
|-------|--------------|----------|--------------------------------------------------------------------------------------------------------------------|
| image | Bitmap | Yes | The image to be rotated |
| mode | RotationMode | Yes | Rotation mode .R90 (90° Clockwise), .R180 (180° Half Rotation) or .R270 (270° Clockwise, aka 90° Counterclockwise) |
### BitmapUtils.getCorrectOrientationMatrix()
Get corrected transform matrix for orientation data in EXIF
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------|
| image | InputStream | Yes | Image input stream |
## Usage FileUtils
Import using
`import com.guhungry.photomanipulator.FileUtils`
### FileUtils.createTempFile()
Create temp file into cache directory with a prefix
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-------------------------------------------------|
| context | Context | Yes | Android context |
| prefix | String | Yes | Temp file name prefix |
| mimeType | String | Yes | Mime type of image. Default = image/jpeg |
### FileUtils.cachePath()
Get cache path of app
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-------------------------------------------------|
| context | Context | Yes | Android context |
### FileUtils.cleanDirectory()
Delete all files in directory with prefix
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-------------------------------------------------|
| directory | File | Yes | Path to clean |
| prefix | String | Yes | File name prefix to match |
### FileUtils.openBitmapInputStream()
Open file from uri as input stream
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|------------------------------------------------------------------------------------------|
| context | File | Yes | Path to clean |
| uri | String | Yes | Uri of image can be remote (https?://) or local (file://, android.res:// and content://) |
## Usage MimeUtils
Import using
`import com.guhungry.photomanipulator.MimeUtils`
### MimeUtils.toExtension()
Get image file extension from mimeType (Support .jpg, .png and .webp)
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-------------------------------------------------|
| mimeType | String | Yes | Image mime type |
### MimeUtils.toCompressFormat()
Get image `Bitmap.CompressFormat` from mimeType (Support .jpg, .png and .webp)
| NAME | TYPE | REQUIRED | DESCRIPTION |
|------------|-----------------------|----------|-------------------------------------------------|
| mimeType | String | Yes | Image mime type |