1.4.1 • Published 3 days ago

react-native-photo-manipulator v1.4.1

Weekly downloads
53
License
MIT
Repository
github
Last release
3 days ago

React Native Photo Manipulator

React Native Image Processing API to edit photo programmatically for Android and iOS.

npm version build

Platform Supported

  • Android
  • iOS

Getting started

For react native 0.60 and above

$ yarn add react-native-photo-manipulator

(or)

$ npm install react-native-photo-manipulator

For react native 0.59 and below

Please read Get Started Guide

Usage

Import library with

import RNPhotoManipulator from 'react-native-photo-manipulator';

API

Method

Crop and resize

Crop image with cropRegion and resize to targetSize if specified

Signature
static crop(image: ImageSource, cropRegion: Rect, targetSize?: Size) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe image
cropRegionRectYesThe region of image to be cropped
targetSizeSizeNoThe target size of result image
mimeType'image/jpeg', 'image/png'NoOutput file format
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const cropRegion = { x: 5, y: 30, height: 400, width: 250 };
const targetSize = { height: 200, width: 150 };

RNPhotoManipulator.crop(image, cropRegion, targetSize).then(path => {
    console.log(`Result image path: ${path}`);
});

Optimize

Save result image with specified quality between 0 - 100 in jpeg format

Signature
static optimize(image: ImageSource, quality: number) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe image
qualitynumberYesThe quality of result image between 0 - 100
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const quality = 90;

RNPhotoManipulator.optimize(image, 90).then(path => {
    console.log(`Result image path: ${path}`);
});

Flip Image

Flip image horizontally, vertically or both

Signature
static flipImage(image: ImageSource, mode: FlipMode) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe background image
modeFlipModeYesFlip mode Horizontal, Vertical or Both
mimeType'image/jpeg', 'image/png'NoOutput file format
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const mode = FlipMode.Vertical;

RNPhotoManipulator.flipImage(image, mode).then(path => {
    console.log(`Result image path: ${path}`);
});

Overlay Image

Overlay image on top of background image

Signature
static overlayImage(image: ImageSource, overlay: ImageSource, position: Point) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe background image
overlayImageSourceYesThe overlay image
positionPointYesThe position of overlay image in background image
mimeType'image/jpeg', 'image/png'NoOutput file format
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const overlay = "https://www.iconfinder.com/icons/1174949/download/png/128";
const position = { x: 5, y: 20 };

RNPhotoManipulator.overlayImage(image, overlay, position).then(path => {
    console.log(`Result image path: ${path}`);
});

Print Text

Print texts into image

Signature
static printText(image: ImageSource, texts: TextOptions[]) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe image
textsTextOptions[]YesThe list of text operations
mimeType'image/jpeg', 'image/png'NoOutput file format
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const texts = [
    { position: { x: 50, y: 30 }, text: "Text 1", textSize: 30, color: "#000000" },
    { position: { x: 50, y: 30 }, text: "Text 1", textSize: 30, color: "#FFFFFF", thickness: 3 }
];

RNPhotoManipulator.printText(image, texts).then(path => {
    console.log(`Result image path: ${path}`);
});

Batch

Crop, resize and do operations (overlay and printText) on image

Signature
static batch(image: ImageSource, operations: PhotoBatchOperations[], cropRegion: Rect, targetSize?: Size, quality?: number) => Promise<string>
ParameterTypeRequiredDescription
imageImageSourceYesThe image
operationsPhotoBatchOperations[]YesThe list of operations
cropRegionRectYesThe region of image to be cropped
targetSizeSizeNoThe target size of result image
qualitynumberNoThe quality of result image between 0 - 100
mimeType'image/jpeg', 'image/png'NoOutput file format
Returns

Promise with image path in cache directory

Example
const image = "https://unsplash.com/photos/qw6qQQyYQpo/download?force=true";
const cropRegion = { x: 5, y: 30, height: 400, width: 250 };
const targetSize = { height: 200, width: 150 };
const operations = [
    { operation: "text", options: { position: { x: 50, y: 30 }, text: "Text 1", textSize: 30, color: "#000000" } },
    { operation: "overlay", overlay: "https://www.iconfinder.com/icons/1174949/download/png/128", position: { x: 5, y: 20 } },
];
const quality = 90;

RNPhotoManipulator.batch(image, operations, cropRegion, targetSize, quality).then(path => {
    console.log(`Result image path: ${path}`);
});

Types

ImageSource

Image resource can be url or require()

TypeDescription
numberImage from require('path/to/image')
stringImage from url supports file://, http://, https:// and ftp://

PhotoBatchOperations

Represent overlay image, print text or flip operation

PhotoBatchOverlay

Overlay image batch operation

PropertyTypeDescription
operation"overlay"
overlayImageSourceThe overlay image
positionPointhe position of overlay image in background image

PhotoBatchPrintText

Print text batch operation

PropertyTypeDescription
operation"text"
optionsTextOptionsThe text attributes

PhotoBatchFlip

Flip image batch operation

PropertyTypeDescription
operation"flip"
modeFlipModeFlip mode Vertical, Horizontal or Both

FlipMode

Enum represent flip Mode

EnumDescription
HorizontalFlip horizontal (y-axis)
VerticalFlip vertical (x-asis)
BothFlip vertical and horizontal

Point

Represent position (x, y) from top-left of image

PropertyTypeDescription
xnumberThe x-axis coordinate from top-left
ynumberThe y-axis coordinate from top-left

Rect

Represent area of region

PropertyTypeDescription
xnumberThe x-axis coordinate from top-left
ynumberThe y-axis coordinate from top-left
widthnumberThe width of the region
heightnumberThe height of the region

Size

Represent size (width, height) of region or image

PropertyTypeDescription
widthnumberThe width of the region
heightnumberThe height of the region

TextOptions

Represent attributes of text such as text, color, size, and etc.

PropertyTypeRequiredDescription
positionPointYesThe position of the text in background image
textstringYesThe value of the text
textSizenumberYesThe size of the text
fontNamestringNoThe font name that can resolve by React NativeiOS: Use "PostScript name"Android: Use filename
colorstringNoThe color of the text
thicknessnumberNoThe thickness (border width) of the region
rotationnumberNoThe rotation of text in degrees
1.4.1

3 days ago

1.4.0

7 days ago

1.3.2

14 days ago

1.3.1

21 days ago

1.2.8

1 month ago

0.0.1-alpha.2

1 month ago

1.2.9

1 month ago

1.2.8-alpha.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.7-rc.0

3 years ago

1.2.5

3 years ago

1.2.5-rc.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

4 years ago

1.2.0

4 years ago

2.0.0-alpha2

4 years ago

2.0.0-alpha1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago