|
1 |
| -# @react-native-community/image-editor |
| 1 | +# react-native-image-editor |
| 2 | + |
| 3 | +Image Editor Native module for React Native. |
2 | 4 |
|
3 | 5 | [![Build Status][build-badge]][build]
|
4 |
| -[![Version][version-badge]][package] |
5 | 6 | [![MIT License][license-badge]][license]
|
6 | 7 | [![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
7 | 8 | [![Lean Core Badge][lean-core-badge]][lean-core-issue]
|
8 | 9 |
|
9 |
| -Image Editor Native module for React Native. |
10 |
| - |
11 |
| -Originally extracted from React Native [`issue#23313`](https://github.com/facebook/react-native/issues/23313) and maintained by the community. |
12 |
| - |
13 | 10 | ## Getting started
|
14 | 11 |
|
15 | 12 | ### Install
|
@@ -38,41 +35,38 @@ import ImageEditor from '@react-native-community/image-editor';
|
38 | 35 |
|
39 | 36 | Crop the image specified by the URI param. If URI points to a remote image, it will be downloaded automatically. If the image cannot be loaded/downloaded, the promise will be rejected.
|
40 | 37 |
|
41 |
| -If the cropping process is successful, the resultant cropped image will be stored in the cache path, and the [`CropResult`](#result-cropresult) returned in the promise will point to the image in the cache path. ⚠️ Remember to delete the cropped image from the cache path when you are done with it. |
| 38 | +If the cropping process is successful, the resultant cropped image will be stored in the cache path, and the URI returned in the promise will point to the image in the cache path. Remember to delete the cropped image from the cache path when you are done with it. |
42 | 39 |
|
43 | 40 | ```ts
|
44 |
| -ImageEditor.cropImage(uri, cropData).then((result) => { |
45 |
| - console.log('Cropped image uri:', result.uri); |
| 41 | +ImageEditor.cropImage(uri, cropData).then((url) => { |
| 42 | + console.log('Cropped image uri', url); |
| 43 | + // In case of Web, the `url` is the base64 string |
46 | 44 | });
|
47 | 45 | ```
|
48 | 46 |
|
49 | 47 | ### `cropData: ImageCropData`
|
50 | 48 |
|
51 |
| -| Name | Type | Description | |
52 |
| -| ------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
53 |
| -| `offset` | `{ x: number, y: number }` | The top-left corner of the cropped image, specified in the original image's coordinate space | |
54 |
| -| `size` | `{ width: number, height: number }` | Size (dimensions) of the cropped image | |
55 |
| -| `displaySize`<br>_(optional)_ | `{ width: number, height: number }` | Size to which you want to scale the cropped image | |
56 |
| -| `resizeMode`<br>_(optional)_ | `'contain' \| 'cover' \| 'stretch' \| 'center'` | Resizing mode to use when scaling the image (iOS only, Android resize mode is always `'cover'`, Web - no support) <br/>**Default value**: `'cover'` | |
57 |
| -| `quality`<br>_(optional)_ | `number` | A value in range `0.0` - `1.0` specifying compression level of the result image. `1` means no compression (highest quality) and `0` the highest compression (lowest quality) <br/>**Default value**: `0.9` | |
58 |
| -| `format`<br>_(optional)_ | `'jpeg' \| 'png' \| 'webp'` | The format of the resulting image.<br/> **Default value**: based on the provided image;<br>if value determination is not possible, `'jpeg'` will be used as a fallback.<br/>`'webp'` isn't supported by iOS. | |
59 |
| -| `includeBase64`<br>_(optional)_ | `boolean` | Indicates if Base64 formatted picture data should also be included in the [`CropResult`](#result-cropresult). <br/>**Default value**: `false` | |
60 |
| -| `headers`<br>_(optional)_ | `object \| Headers` | An object or [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) interface representing the HTTP headers to send along with the request for a remote image. | |
61 |
| - |
62 |
| -### `result: CropResult` |
63 |
| - |
64 |
| -| Name | Type | Description | |
65 |
| -| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
66 |
| -| `uri` | `string` | The path to the image file (example: `'file:///data/user/0/.../image.jpg'`)<br> **WEB:** `uri` is the data URI string (example `'data:image/jpeg;base64,/4AAQ...AQABAA'`) | |
67 |
| -| `path` | `string` | The URI of the image (example: `'/data/user/0/.../image.jpg'`)<br> **WEB:** `path` is the blob URL (example `'blob:https://example.com/43ff7a16...e46b1'`) | |
68 |
| -| `name` | `string` | The name of the image file. (example: `'image.jpg'`) | |
69 |
| -| `width` | `number` | The width of the image in pixels | |
70 |
| -| `height` | `number` | Height of the image in pixels | |
71 |
| -| `size` | `number` | The size of the image in bytes | |
72 |
| -| `type` | `string` | The MIME type of the image (`'image/jpeg'`, `'image/png'`, `'image/webp'`) | |
73 |
| -| `base64`<br>_(optional)_ | `string` | The base64-encoded image data example: `'/9j/4AAQSkZJRgABAQAAAQABAAD'`<br>if you need data URI as the `source` for an `Image` element for example, you can use `data:${type};base64,${base64}` | |
74 |
| - |
75 |
| -For more advanced usage check our [example app](/example/src/App.tsx). |
| 49 | +| Property | Required | Description | |
| 50 | +| ------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 51 | +| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space | |
| 52 | +| `size` | Yes | Size (dimensions) of the cropped image | |
| 53 | +| `displaySize` | No | Size to which you want to scale the cropped image | |
| 54 | +| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' | |
| 55 | +| `quality` | No | The quality of the resulting image, expressed as a value from `0.0` to `1.0`. <br/>The value `0.0` represents the maximum compression (or lowest quality) while the value `1.0` represents the least compression (or best quality).<br/>iOS supports only `JPEG` format, while Android/Web supports both `JPEG`, `WEBP` and `PNG` formats.<br/>**Default value**: (iOS: `1`), (Android: `0.9`) | |
| 56 | +| `format` | No | **(WEB ONLY)** The format of the resulting image, possible values are `jpeg`, `png`, `webp`, **Default value**: `jpeg` | |
| 57 | + |
| 58 | +```ts |
| 59 | +cropData: ImageCropData = { |
| 60 | + offset: {x: number, y: number}, |
| 61 | + size: {width: number, height: number}, |
| 62 | + displaySize: {width: number, height: number}, |
| 63 | + resizeMode: 'contain' | 'cover' | 'stretch', |
| 64 | + quality: number, // 0...1 |
| 65 | + format: 'jpeg' | 'png' | 'webp' // web only |
| 66 | +}; |
| 67 | +``` |
| 68 | + |
| 69 | +For more advanced usage check our [example app](https://github.com/react-native-oh-library/RNOHDCS/tree/main/ImageEditorDemo). |
76 | 70 |
|
77 | 71 | <!-- badges -->
|
78 | 72 |
|
|
0 commit comments