From 87be54cbef3784014c10b088f991ae054887292e Mon Sep 17 00:00:00 2001 From: Joschka Schulz Date: Thu, 21 Jun 2018 20:18:05 +0200 Subject: [PATCH] Revert "Merge pull request #43 from ASBConsulting/rotation" This reverts commit 476b6b12fbe8d2cf95f551737c16bb3c3a13e37b, reversing changes made to a87a16d2517cb6f46e6aaf984fedd7b062a128a3. --- package.json | 4 +- plugin.xml | 2 - src/android/ImageResizer.java | 84 ++--------------------------------- src/ios/ImageResizer.h | 1 - src/ios/ImageResizer.m | 48 +------------------- 5 files changed, 6 insertions(+), 133 deletions(-) diff --git a/package.json b/package.json index 8ce1904..093f5e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "cordova-plugin-image-resizer", - "version": "0.1.1", + "name": "cordova-plugin-simple-image-resizer", + "version": "0.1.0", "description": "Plugin for resizing images only with the uri of the image.", "cordova": { "id": "cordova-plugin-image-resizer", diff --git a/plugin.xml b/plugin.xml index a8605ac..b00a140 100644 --- a/plugin.xml +++ b/plugin.xml @@ -25,8 +25,6 @@ - - diff --git a/src/android/ImageResizer.java b/src/android/ImageResizer.java index 5a6a5fa..f0a6de7 100644 --- a/src/android/ImageResizer.java +++ b/src/android/ImageResizer.java @@ -3,11 +3,8 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.media.ExifInterface; import android.net.Uri; import android.os.Environment; -import android.util.Base64; import android.util.Log; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; @@ -17,7 +14,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -33,8 +29,6 @@ public class ImageResizer extends CordovaPlugin { private int quality; private int width; private int height; - private boolean fixRotation = false; - private boolean base64 = false; public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try { @@ -57,58 +51,14 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo quality = jsonObject.getInt("quality"); width = jsonObject.getInt("width"); height = jsonObject.getInt("height"); - if(jsonObject.has("fixRotation")){ - fixRotation = jsonObject.getBoolean("fixRotation"); - } - if(jsonObject.has("base64")){ - base64 = jsonObject.getBoolean("base64"); - } // load the image from uri Bitmap bitmap = loadScaledBitmapFromUri(uri, width, height); - if(bitmap == null){ - Log.e("Protonet", "There was an error reading the image"); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); - return false; - } + // save the image as jpeg on the device + Uri scaledFile = saveFile(bitmap); - if(fixRotation){ - // Get the exif rotation in degrees, create a transformation matrix, and rotate - // the bitmap - int rotation = getRoationDegrees(getRotation(uri)); - Matrix matrix = new Matrix(); - if (rotation != 0f) {matrix.preRotate(rotation);} - bitmap = Bitmap.createBitmap( - bitmap, - 0, - 0, - bitmap.getWidth(), - bitmap.getHeight(), - matrix, - true); - } - - if(base64){ - // convert the bitmap to a b64 string and return - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(CompressFormat.JPEG, 100, byteArrayOutputStream); - byte[] byteArray = byteArrayOutputStream .toByteArray(); - String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, - "data:image/jpeg;base64,"+encoded)); - }else { - // save the image as jpeg on the device - Uri scaledFile = saveFile(bitmap); - - if(scaledFile == null){ - Log.e("Protonet", "There was an error saving the thumbnail"); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); - return false; - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, - scaledFile.toString())); - } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, scaledFile.toString())); return true; } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); @@ -121,34 +71,6 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo return false; } - /** - * Gets the image rotation from the image EXIF Data - * - * @param exifOrientation ExifInterface.ORIENTATION_* representation of the rotation - * @return the rotation in degrees - */ - private int getRoationDegrees(int exifOrientation){ - if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } - else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; } - else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; } - return 0; - } - - /** - * Gets the image rotation from the image EXIF Data - * - * @param uriString the URI of the image to get the rotation for - * @return ExifInterface.ORIENTATION_* representation of the rotation - */ - private int getRotation(String uriString){ - try { - ExifInterface exif = new ExifInterface(uriString); - return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); - } catch (IOException e) { - return ExifInterface.ORIENTATION_NORMAL; - } - } - /** * Loads a Bitmap of the given android uri path * diff --git a/src/ios/ImageResizer.h b/src/ios/ImageResizer.h index 9269270..12499a2 100644 --- a/src/ios/ImageResizer.h +++ b/src/ios/ImageResizer.h @@ -2,5 +2,4 @@ #import @interface ImageResizer : CDVPlugin - (void) resize:(CDVInvokedUrlCommand*)command; -- (UIImage*) rotateImage:(UIImage*) image withRotation:(int) rotation; @end diff --git a/src/ios/ImageResizer.m b/src/ios/ImageResizer.m index ab4eac6..4be73e2 100644 --- a/src/ios/ImageResizer.m +++ b/src/ios/ImageResizer.m @@ -29,32 +29,12 @@ - (void) resize:(CDVInvokedUrlCommand*)command NSString* fileName = [arguments objectForKey:@"fileName"]; BOOL asBase64 = [[arguments objectForKey:@"base64"] boolValue]; - BOOL fixRotation = [[arguments objectForKey:@"fixRotation"] boolValue]; // //Get the image from the path NSURL* imageURL = [NSURL URLWithString:imageUrlString]; sourceImage = [UIImage imageWithData: [NSData dataWithContentsOfURL: imageURL]]; - - int rotation = 0; - - switch ([sourceImage imageOrientation]) { - case UIImageOrientationUp: - rotation = 0; - break; - case UIImageOrientationDown: - rotation = 180; - break; - case UIImageOrientationLeft: - rotation = 270; - break; - case UIImageOrientationRight: - rotation = 90; - break; - default: - break; - } - + PHFetchResult *savedAssets = [PHAsset fetchAssetsWithLocalIdentifiers:@[fileName] options:nil]; [savedAssets enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) { //this gets called for every asset from its localIdentifier you saved @@ -107,10 +87,6 @@ - (void) resize:(CDVInvokedUrlCommand*)command tempImage = UIGraphicsGetImageFromCurrentImageContext(); NSLog(@"image resizer:%@", (tempImage ? @"image exsist" : @"null" )); - - if(fixRotation){ - tempImage = [self rotateImage:tempImage withRotation:rotation]; - } UIGraphicsEndImageContext(); NSData *imageData = UIImageJPEGRepresentation(tempImage, [quality floatValue] / 100.0f ); @@ -143,26 +119,4 @@ - (void) resize:(CDVInvokedUrlCommand*)command [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; } -- (UIImage*) rotateImage:(UIImage*) image withRotation:(int) rotation{ - CGFloat rot = rotation * M_PI / 180; - - // Calculate Destination Size - CGAffineTransform t = CGAffineTransformMakeRotation(rot); - CGRect sizeRect = (CGRect) {.size = image.size}; - CGRect destRect = CGRectApplyAffineTransform(sizeRect, t); - CGSize destinationSize = destRect.size; - - // Draw image - UIGraphicsBeginImageContext(destinationSize); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextTranslateCTM(context, destinationSize.width / 2.0f, destinationSize.height / 2.0f); - CGContextRotateCTM(context, rot); - [image drawInRect:CGRectMake(-image.size.width / 2.0f, -image.size.height / 2.0f, image.size.width, image.size.height)]; - - // Save image - UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return newImage; -} - @end