diff --git a/README.md b/README.md index 67a79fa..c3e4ae8 100755 --- a/README.md +++ b/README.md @@ -47,14 +47,14 @@ ImageEditor.cropImage(uri, cropData).then((url) => { ### `cropData: ImageCropData` -| Property | Required | Description | -| ------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space | -| `size` | Yes | Size (dimensions) of the cropped image | -| `displaySize` | No | Size to which you want to scale the cropped image | -| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' | -| `quality` | No | The quality of the resulting image, expressed as a value from `0.0` to `1.0`.
The value `0.0` represents the maximum compression (or lowest quality) while the value `1.0` represents the least compression (or best quality).
iOS supports only `JPEG` format, while Android/Web supports both `JPEG`, `WEBP` and `PNG` formats.
**Default value**: (iOS: `1`), (Android: `0.9`) | -| `format` | No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`.
**Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback.
`webp` isn't supported by iOS. | +| Property | Required | Description | +| ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space | +| `size` | Yes | Size (dimensions) of the cropped image | +| `displaySize` | No | Size to which you want to scale the cropped image | +| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' | +| `quality` | No | The quality of the resulting image, expressed as a value from `0.0` to `1.0`.
The value `0.0` represents the maximum compression (or lowest quality) while the value `1.0` represents the least compression (or best quality).
iOS supports only `JPEG` format, while Android/Web supports both `JPEG`, `WEBP` and `PNG` formats.
**Default value**: `0.9` | +| `format` | No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`.
**Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback.
`webp` isn't supported by iOS. | ```ts cropData: ImageCropData = { diff --git a/ios/RNCImageEditor.mm b/ios/RNCImageEditor.mm index 148c147..4102a4f 100644 --- a/ios/RNCImageEditor.mm +++ b/ios/RNCImageEditor.mm @@ -23,6 +23,8 @@ #import "RCTImageUtils.h" #endif +#define DEFAULT_COMPRESSION_QUALITY 0.9 + @implementation RNCImageEditor RCT_EXPORT_MODULE() @@ -57,7 +59,7 @@ - (void) cropImage:(NSString *)uri } NSString *displaySize = data.resizeMode(); NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: uri]]; - CGFloat compressionQuality = 1; + CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY; if (data.quality().has_value()) { compressionQuality = *data.quality(); } @@ -75,7 +77,7 @@ - (void) cropImage:(NSString *)uri if(displaySize){ targetSize = [RCTConvert CGSize:cropData[@"displaySize"]]; } - CGFloat compressionQuality = 1; + CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY; if(cropData[@"quality"]){ compressionQuality = [RCTConvert CGFloat:cropData[@"quality"]]; } diff --git a/src/index.web.ts b/src/index.web.ts index 761a642..066870e 100644 --- a/src/index.web.ts +++ b/src/index.web.ts @@ -48,6 +48,8 @@ function fetchImage(imgSrc: string): Promise { }); } +const DEFAULT_COMPRESSION_QUALITY = 0.9; + class ImageEditor { static cropImage(imgSrc: string, cropData: ImageCropData): Promise { /** @@ -57,7 +59,7 @@ class ImageEditor { const canvas = drawImage(image, cropData); return canvas.toDataURL( `image/${cropData.format ?? 'jpeg'}`, - cropData.quality ?? 1 + cropData.quality ?? DEFAULT_COMPRESSION_QUALITY ); }); }