You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-35Lines changed: 26 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,47 +36,38 @@ import ImageEditor from '@react-native-community/image-editor';
36
36
37
37
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.
38
38
39
-
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.
39
+
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.
40
40
41
41
```ts
42
-
ImageEditor.cropImage(uri, cropData).then(
43
-
({
44
-
uri, // the path to the image file (example: 'file:///data/user/0/.../image.jpg')
45
-
path, // the URI of the image (example: '/data/user/0/.../image.jpg')
46
-
name, // the name of the image file. (example: 'image.jpg')
47
-
width, // the width of the image in pixels
48
-
height, // height of the image in pixels
49
-
size, // the size of the image in bytes
50
-
}) => {
51
-
console.log('Cropped image uri:', uri);
52
-
// WEB has different response:
53
-
// - `uri` is the base64 string (example `data:image/jpeg;base64,/4AAQ...AQABAA`)
54
-
// - `path` is the blob URL (example `blob:https://example.com/43ff7a16...e46b1`)
|`offset`| Yes | The top-left corner of the cropped image, specified in the original image's coordinate space |
64
-
|`size`| Yes | Size (dimensions) of the cropped image |
65
-
|`displaySize`| No | Size to which you want to scale the cropped image |
66
-
|`resizeMode`| No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always `'cover'`, Web - no support) **Default value**: `'cover'`|
67
-
|`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**: `0.9`|
68
-
|`format`| No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`. <br/> **Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback. <br/> `webp` isn't supported by iOS. |
|`offset`|`{ x: number, y: number }`| The top-left corner of the cropped image, specified in the original image's coordinate space |
52
+
|`size`|`{ width: number, height: number }`| Size (dimensions) of the cropped image |
53
+
|`displaySize`<br>_(optional)_|`{ width: number, height: number }`| Size to which you want to scale the cropped image |
54
+
|`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'`|
55
+
|`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`|
56
+
|`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. |
57
+
|`includeBase64`<br>_(optional)_|`boolean`| Indicates if Base64 formatted picture data should also be included in the [`CropResult`](#result-cropresult). <br/>**Default value**: `false`|
|`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'`) |
64
+
|`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'`) |
65
+
|`name`|`string`| The name of the image file. (example: `'image.jpg'`) |
66
+
|`width`|`number`| The width of the image in pixels |
67
+
|`height`|`number`| Height of the image in pixels |
68
+
|`size`|`number`| The size of the image in bytes |
69
+
|`type`|`string`| The MIME type of the image (`'image/jpeg'`, `'image/png'`, `'image/webp'`) |
70
+
|`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}`|
80
71
81
72
For more advanced usage check our [example app](/example/src/App.tsx).
0 commit comments