Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ImageEditor.cropImage(uri, cropData).then((url) => {
| `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' |
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always `'cover'`, Web - no support) **Default value**: `'cover'` |
| `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` |
| `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. |

Expand Down
5 changes: 3 additions & 2 deletions ios/RNCImageEditor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

#define DEFAULT_COMPRESSION_QUALITY 0.9
#define DEFAULT_RESIZE_MODE "cover"

@implementation RNCImageEditor

Expand Down Expand Up @@ -59,7 +60,7 @@ - (void) cropImage:(NSString *)uri
// in pixels
displaySize = [RCTConvert CGSize:@{ @"width": @(rawDisplaySize.width()), @"height": @(rawDisplaySize.height()) }];
}
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:data.resizeMode() ?: @"contain"];
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:data.resizeMode() ?: @(DEFAULT_RESIZE_MODE)];
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: uri]];
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
if (data.quality().has_value()) {
Expand All @@ -74,7 +75,7 @@ - (void) cropImage:(NSString *)uri
NSString *format = cropData[@"format"];
CGSize size = [RCTConvert CGSize:cropData[@"size"]];
CGPoint offset = [RCTConvert CGPoint:cropData[@"offset"]];
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:cropData[@"resizeMode"] ?: @"contain"];
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:cropData[@"resizeMode"] ?: @(DEFAULT_RESIZE_MODE)];
CGSize displaySize = CGSizeZero;
BOOL hasDisplaySizeValue = cropData[@"displaySize"];
if(hasDisplaySizeValue){
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type ImageCropDataFromSpec = Parameters<Spec['cropImage']>[1];
export interface ImageCropData
extends Omit<ImageCropDataFromSpec, 'resizeMode' | 'format'> {
format?: 'png' | 'jpeg' | 'webp';
resizeMode?: 'contain' | 'cover' | 'stretch';
resizeMode?: 'contain' | 'cover' | 'stretch' | 'center';
// ^^^ codegen doesn't support union types yet
// so to provide more type safety we override the type here
}