From 08afe72f695ac2c9cf780c1802373865143245af Mon Sep 17 00:00:00 2001 From: Sammy Date: Sat, 25 Mar 2017 00:30:13 -0500 Subject: [PATCH 01/12] added react native 0.40 headers --- ReactNativeImageCropping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactNativeImageCropping.h b/ReactNativeImageCropping.h index 19b67e0..27c42f0 100644 --- a/ReactNativeImageCropping.h +++ b/ReactNativeImageCropping.h @@ -1,4 +1,4 @@ -#import "RCTBridgeModule.h" +#import #import "TOCropView.h" #import From 0d60974530f61a4a0f382b3059019eb20955670c Mon Sep 17 00:00:00 2001 From: Sammy Date: Sat, 25 Mar 2017 00:30:56 -0500 Subject: [PATCH 02/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4da687..070e0dc 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,6 @@ "TOCropViewController": "git+https://github.com/meznaric/TOCropViewController.git" }, "peerDependencies": { - "react-native": "^0.28.0" + "react-native": "^0.40.0" } } From c5d3d47b18aee7ab5621d066d44efe69ce29f8e8 Mon Sep 17 00:00:00 2001 From: Sammy Date: Sat, 25 Mar 2017 00:31:39 -0500 Subject: [PATCH 03/12] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 070e0dc..9dfe467 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.0.0", + "version": "1.1.0", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", @@ -9,6 +9,6 @@ "TOCropViewController": "git+https://github.com/meznaric/TOCropViewController.git" }, "peerDependencies": { - "react-native": "^0.40.0" + "react-native": ">=0.40.0" } } From 14011f6008cdd1eb4fcb9d22b5e234056532b19e Mon Sep 17 00:00:00 2001 From: Sammy Date: Sat, 25 Mar 2017 00:41:38 -0500 Subject: [PATCH 04/12] Update README.md --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index be39148..9a2c842 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,10 @@ If you get stuck open an issue. It's the first time I've published react native ### Import module ```javascript -const React = require('react-native'); -const {ReactNativeImageCropping} = React.NativeModules; +import { + NativeModules, +} from 'react-native' +const { ReactNativeImageCropping } = NativeModules; ``` ### Crop the image @@ -38,12 +40,12 @@ It is using RCTImageLoader so it should be able to crop any image that react kno const originalImage = require('CrazyFlowers.jpg'); ReactNativeImageCropping - .cropImageWithUrl(originalImage.uri) + .cropImageWithUrl(originalImage.uri) .then(image => { - //Image is saved in NSTemporaryDirectory! - //image = {uri, width, height} - }, - err => console.log(b)); + //Image is saved in NSTemporaryDirectory! + //image = {uri, width, height} + }) + .catch(err => { console.log(err) }) ``` #### Lock to specific aspect ratio: @@ -63,15 +65,15 @@ Available aspect ratios: Example: ```javascript -let aspectRatio = ReactNativeImageCropping.AspectRatioSquare; +const aspectRatio = ReactNativeImageCropping.AspectRatioSquare; ReactNativeImageCropping .cropImageWithUrlAndAspect(imageUrl, aspectRatio) .then(image => { //Image is saved in NSTemporaryDirectory! //image = {uri, width, height} - }, - err => console.log(b)); + }) + .catch(err => { console.log(err) }) ``` From fb5e84b8de4d7d151811309462ce193aa24e7151 Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:17:34 -0500 Subject: [PATCH 05/12] downsample before crop --- ReactNativeImageCropping.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index ebeaf75..81838d1 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -88,6 +88,18 @@ - (NSDictionary *)constantsToExport - (void)handleImageLoad:(UIImage *)image { + // hardcoded downsample of image + float oldWidth = image.size.width; + float scaleFactor = 600 / oldWidth; + + float newHeight = image.size.height * scaleFactor; + float newWidth = oldWidth * scaleFactor; + + UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); + [image drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; + UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:image]; cropViewController.delegate = self; From df10fbb1933ae73564bd74c3bdb25e4b1ce4e4cf Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:18:10 -0500 Subject: [PATCH 06/12] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9dfe467..dc58eb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.1.0", + "version": "1.1.1", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", From dcaec4d6a22eee1d2ba0551818d65e28d8f0855c Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:25:15 -0500 Subject: [PATCH 07/12] fixed scaling --- ReactNativeImageCropping.m | 27 +++++++++++++++++---------- package.json | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index 81838d1..d7ed2d3 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -90,18 +90,25 @@ - (void)handleImageLoad:(UIImage *)image { // hardcoded downsample of image float oldWidth = image.size.width; - float scaleFactor = 600 / oldWidth; - - float newHeight = image.size.height * scaleFactor; - float newWidth = oldWidth * scaleFactor; - - UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); - [image drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; - UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); + UIImage *scaledImage = nil; + if (oldWidth > 600) { + float scaleFactor = 600 / oldWidth; + + float newHeight = image.size.height * scaleFactor; + float newWidth = oldWidth * scaleFactor; + + UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); + [image drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; + scaledImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + } + else { + scaledImage = image + } UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; - TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:image]; + TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:scaledImage]; cropViewController.delegate = self; if(self.aspectRatio) { diff --git a/package.json b/package.json index dc58eb0..cfdf476 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.1.1", + "version": "1.1.2", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", From 2d7f8dc186bd0f0e396f958dc15d85c5701b47f4 Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:26:36 -0500 Subject: [PATCH 08/12] added missing semicolon --- ReactNativeImageCropping.m | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index d7ed2d3..82c70f8 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -104,7 +104,7 @@ - (void)handleImageLoad:(UIImage *)image { } else { - scaledImage = image + scaledImage = image; } UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; diff --git a/package.json b/package.json index cfdf476..76bd4a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.1.2", + "version": "1.1.3", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", From 4f5dbecf085d304cca3f15984674e3ce19f55cb9 Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:28:36 -0500 Subject: [PATCH 09/12] cleaner code --- ReactNativeImageCropping.m | 5 +---- package.json | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index 82c70f8..cbba3a5 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -90,7 +90,7 @@ - (void)handleImageLoad:(UIImage *)image { // hardcoded downsample of image float oldWidth = image.size.width; - UIImage *scaledImage = nil; + UIImage *scaledImage = image; if (oldWidth > 600) { float scaleFactor = 600 / oldWidth; @@ -103,9 +103,6 @@ - (void)handleImageLoad:(UIImage *)image { UIGraphicsEndImageContext(); } - else { - scaledImage = image; - } UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:scaledImage]; diff --git a/package.json b/package.json index 76bd4a0..0fadd87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.1.3", + "version": "1.1.4", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", From 9f387dfc8d8a71cc4b337cf66df9fd63f192c011 Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:44:17 -0500 Subject: [PATCH 10/12] increase image size --- ReactNativeImageCropping.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index cbba3a5..b90e83a 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -91,8 +91,8 @@ - (void)handleImageLoad:(UIImage *)image { // hardcoded downsample of image float oldWidth = image.size.width; UIImage *scaledImage = image; - if (oldWidth > 600) { - float scaleFactor = 600 / oldWidth; + if (oldWidth > 800) { + float scaleFactor = 800 / oldWidth; float newHeight = image.size.height * scaleFactor; float newWidth = oldWidth * scaleFactor; From acc5b8a021f32f1d2f9a5a295dcc0f66b8bbfc4f Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Wed, 10 May 2017 16:44:48 -0500 Subject: [PATCH 11/12] bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0fadd87..7a6dd71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-cropping", - "version": "1.1.4", + "version": "1.1.5", "keywords": "react-native image cropping", "description": "Simple image cropping library for react-native.", "license": "MIT", From 43f9e2b75be9742990222ac0f1e56b881db1849f Mon Sep 17 00:00:00 2001 From: Sammy Yousif Date: Thu, 8 Jun 2017 16:16:03 -0400 Subject: [PATCH 12/12] switched from png to jpeg --- ReactNativeImageCropping.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ReactNativeImageCropping.m b/ReactNativeImageCropping.m index b90e83a..a9c04f7 100644 --- a/ReactNativeImageCropping.m +++ b/ReactNativeImageCropping.m @@ -129,10 +129,10 @@ - (void)cropViewController:(TOCropViewController *)cropViewController didCropToI [cropViewController dismissViewControllerAnimated:YES completion:nil]; }); - NSData *pngData = UIImagePNGRepresentation(image); - NSString *fileName = [NSString stringWithFormat:@"memegenerator-crop-%lf.png", [NSDate timeIntervalSinceReferenceDate]]; - NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; //Add the file name) - [pngData writeToFile:filePath atomically:YES]; + NSData *jpgData = UIImageJPEGRepresentation(image, 80); + NSString *fileName = [NSString stringWithFormat:@"resized-%lf.jpg", [NSDate timeIntervalSinceReferenceDate]]; + NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; + [jpgData writeToFile:filePath atomically:YES]; NSNumber *width = [NSNumber numberWithFloat:image.size.width]; NSNumber *height = [NSNumber numberWithFloat:image.size.height];