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
{{ message }}
Repository navigation
Commit 07a4eb9
Browse filesBrowse the repository at this point in the historyBrowse files
|`type`|`string`| The MIME type of the image (`'image/jpeg'`, `'image/png'`, `'image/webp'`) |
87
91
|`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}`|
88
92
89
-
For more advanced usage check our [example app](/example/src/App.tsx).
93
+
## Example app
94
+
95
+
The [example app](/example) shows every `cropImage` option, plus a cache lab for `Image.prefetch` / `<Image>` cache reuse. See its [README](/example/README.md) for how to run it.
96
+
97
+
> [!NOTE]
98
+
> The example UI (crop box, controls, result view) is **not part of this library**. It's example code built with plain React Native. The library itself only provides `ImageEditor.cropImage()`.
A playground for [`@react-native-community/image-editor`](../README.md) that exercises every option of `ImageEditor.cropImage`.
4
+
5
+
> [!NOTE]
6
+
> The UI in this app (crop box, controls, result inspector, cache lab) is **not part of the library**. The library only provides `ImageEditor.cropImage()`. The UI is plain React Native code you're free to copy.
7
+
8
+
| Editor | Output options | Result | Cache lab |
9
+
| :---: | :---: | :---: | :---: |
10
+
| <imgsrc="./screenshots/editor.jpg"width="200"alt="Crop area with a draggable crop box and aspect ratio presets" /> | <imgsrc="./screenshots/options.jpg"width="200"alt="Format, quality, base64 and displaySize options" /> | <imgsrc="./screenshots/result.jpg"width="200"alt="Cropped image with its dimensions, type, size and base64" /> | <imgsrc="./screenshots/cache-lab.jpg"width="200"alt="Cache lab log showing prefetch followed by a fast crop" /> |
11
+
12
+
## What it covers
13
+
14
+
-**Sources**: a remote URL, a remote URL with custom `headers`, a 4000×3000 image, a portrait image, the previous result as a `file://` URI, and the previous result's base64 as a `data:` URI.
15
+
-**Crop area**: drag the box to move it and its corners to resize it, with aspect ratio presets (Free, 1:1, 4:3, 3:4, 16:9). Offset and size are shown in the original image's pixels, which is what `cropImage` expects.
16
+
-**Output options**: `format`, `quality`, `includeBase64`, `displaySize` and `resizeMode`.
17
+
-**Result**: preview, dimensions, MIME type, file size, path, base64 preview and the time `cropImage` took.
18
+
-**Cache lab**: `Image.queryCache`, `Image.prefetch`, cropping a URL without displaying it, rendering it with `<Image>`, and an invalid URL to check that the promise rejects. Use it to check that `cropImage` reuses the image already cached by `Image.prefetch` / `<Image>`.
19
+
20
+
Platform differences are labeled in the UI: iOS writes only JPEG or PNG (`webp` falls back to JPEG), and Android ignores `resizeMode`.
21
+
22
+
## Running
23
+
24
+
The app links the library from the repository root (`"@react-native-community/image-editor": "link:.."`), so changes to `../src`, `../ios` and `../android` are picked up directly. Metro watches the root folder (see [`metro.config.js`](./metro.config.js)).
25
+
26
+
```sh
27
+
cd example
28
+
yarn install
29
+
```
30
+
31
+
### iOS
32
+
33
+
```sh
34
+
cd ios && bundle install && bundle exec pod install &&cd ..
35
+
yarn ios
36
+
```
37
+
38
+
### Android
39
+
40
+
```sh
41
+
yarn android
42
+
```
43
+
44
+
Metro starts automatically. To start it yourself, run `yarn start`.
45
+
46
+
## Code map
47
+
48
+
| File | What it does |
49
+
| --- | --- |
50
+
|[`src/App.tsx`](./src/App.tsx)| Screen state and the `ImageEditor.cropImage` call |
51
+
|[`src/components/CropArea.tsx`](./src/components/CropArea.tsx)| Image with a draggable, resizable crop box (`PanResponder`) |
52
+
|[`src/components/ResultCard.tsx`](./src/components/ResultCard.tsx)| Shows the `CropResult`|
0 commit comments