Skip to content

Commit c39bc48

Browse files
committed
feature: Use the default quality: 0.9 value across all platforms
1 parent 4f7ec34 commit c39bc48

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ ImageEditor.cropImage(uri, cropData).then((url) => {
4747

4848
### `cropData: ImageCropData`
4949

50-
| Property | Required | Description |
51-
| ------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52-
| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space |
53-
| `size` | Yes | Size (dimensions) of the cropped image |
54-
| `displaySize` | No | Size to which you want to scale the cropped image |
55-
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' |
56-
| `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`) |
57-
| `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. |
50+
| Property | Required | Description |
51+
| ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52+
| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space |
53+
| `size` | Yes | Size (dimensions) of the cropped image |
54+
| `displaySize` | No | Size to which you want to scale the cropped image |
55+
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' |
56+
| `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` |
57+
| `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. |
5858

5959
```ts
6060
cropData: ImageCropData = {

ios/RNCImageEditor.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#import "RCTImageUtils.h"
2424
#endif
2525

26+
#define DEFAULT_COMPRESSION_QUALITY 0.9
27+
2628
@implementation RNCImageEditor
2729

2830
RCT_EXPORT_MODULE()
@@ -57,7 +59,7 @@ - (void) cropImage:(NSString *)uri
5759
}
5860
NSString *displaySize = data.resizeMode();
5961
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: uri]];
60-
CGFloat compressionQuality = 1;
62+
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
6163
if (data.quality().has_value()) {
6264
compressionQuality = *data.quality();
6365
}
@@ -75,7 +77,7 @@ - (void) cropImage:(NSString *)uri
7577
if(displaySize){
7678
targetSize = [RCTConvert CGSize:cropData[@"displaySize"]];
7779
}
78-
CGFloat compressionQuality = 1;
80+
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
7981
if(cropData[@"quality"]){
8082
compressionQuality = [RCTConvert CGFloat:cropData[@"quality"]];
8183
}

src/index.web.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function fetchImage(imgSrc: string): Promise<HTMLImageElement> {
4848
});
4949
}
5050

51+
const QUALITY_DEFAULT = 0.9;
52+
5153
class ImageEditor {
5254
static cropImage(imgSrc: string, cropData: ImageCropData): Promise<string> {
5355
/**
@@ -57,7 +59,7 @@ class ImageEditor {
5759
const canvas = drawImage(image, cropData);
5860
return canvas.toDataURL(
5961
`image/${cropData.format ?? 'jpeg'}`,
60-
cropData.quality ?? 1
62+
cropData.quality ?? QUALITY_DEFAULT
6163
);
6264
});
6365
}

0 commit comments

Comments
 (0)