Skip to content

Commit 87be54c

Browse files
committed
Revert "Merge pull request #43 from ASBConsulting/rotation"
This reverts commit 476b6b1, reversing changes made to a87a16d.
1 parent fe27fff commit 87be54c

File tree

5 files changed

+6
-133
lines changed

5 files changed

+6
-133
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "cordova-plugin-image-resizer",
3-
"version": "0.1.1",
2+
"name": "cordova-plugin-simple-image-resizer",
3+
"version": "0.1.0",
44
"description": "Plugin for resizing images only with the uri of the image.",
55
"cordova": {
66
"id": "cordova-plugin-image-resizer",

plugin.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
</config-file>
2626

2727
<source-file src="src/android/ImageResizer.java" target-dir="src/info/protonet/imageresizer" />
28-
<preference name="ANDROID_EXIFINTERFACES_VERSION" default="27.+"/>
29-
<framework src="com.android.support:exifinterface:$ANDROID_EXIFINTERFACES_VERSION"/>
3028
</platform>
3129

3230
<platform name="ios">

src/android/ImageResizer.java

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import android.graphics.Bitmap;
44
import android.graphics.Bitmap.CompressFormat;
55
import android.graphics.BitmapFactory;
6-
import android.graphics.Matrix;
7-
import android.media.ExifInterface;
86
import android.net.Uri;
97
import android.os.Environment;
10-
import android.util.Base64;
118
import android.util.Log;
129
import org.apache.cordova.CallbackContext;
1310
import org.apache.cordova.CordovaPlugin;
@@ -17,7 +14,6 @@
1714
import org.json.JSONException;
1815
import org.json.JSONObject;
1916

20-
import java.io.ByteArrayOutputStream;
2117
import java.io.File;
2218
import java.io.FileNotFoundException;
2319
import java.io.FileOutputStream;
@@ -33,8 +29,6 @@ public class ImageResizer extends CordovaPlugin {
3329
private int quality;
3430
private int width;
3531
private int height;
36-
private boolean fixRotation = false;
37-
private boolean base64 = false;
3832

3933
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
4034
try {
@@ -57,58 +51,14 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
5751
quality = jsonObject.getInt("quality");
5852
width = jsonObject.getInt("width");
5953
height = jsonObject.getInt("height");
60-
if(jsonObject.has("fixRotation")){
61-
fixRotation = jsonObject.getBoolean("fixRotation");
62-
}
63-
if(jsonObject.has("base64")){
64-
base64 = jsonObject.getBoolean("base64");
65-
}
6654

6755
// load the image from uri
6856
Bitmap bitmap = loadScaledBitmapFromUri(uri, width, height);
6957

70-
if(bitmap == null){
71-
Log.e("Protonet", "There was an error reading the image");
72-
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
73-
return false;
74-
}
58+
// save the image as jpeg on the device
59+
Uri scaledFile = saveFile(bitmap);
7560

76-
if(fixRotation){
77-
// Get the exif rotation in degrees, create a transformation matrix, and rotate
78-
// the bitmap
79-
int rotation = getRoationDegrees(getRotation(uri));
80-
Matrix matrix = new Matrix();
81-
if (rotation != 0f) {matrix.preRotate(rotation);}
82-
bitmap = Bitmap.createBitmap(
83-
bitmap,
84-
0,
85-
0,
86-
bitmap.getWidth(),
87-
bitmap.getHeight(),
88-
matrix,
89-
true);
90-
}
91-
92-
if(base64){
93-
// convert the bitmap to a b64 string and return
94-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
95-
bitmap.compress(CompressFormat.JPEG, 100, byteArrayOutputStream);
96-
byte[] byteArray = byteArrayOutputStream .toByteArray();
97-
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
98-
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
99-
"data:image/jpeg;base64,"+encoded));
100-
}else {
101-
// save the image as jpeg on the device
102-
Uri scaledFile = saveFile(bitmap);
103-
104-
if(scaledFile == null){
105-
Log.e("Protonet", "There was an error saving the thumbnail");
106-
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
107-
return false;
108-
}
109-
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
110-
scaledFile.toString()));
111-
}
61+
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, scaledFile.toString()));
11262
return true;
11363
} else {
11464
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
@@ -121,34 +71,6 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
12171
return false;
12272
}
12373

124-
/**
125-
* Gets the image rotation from the image EXIF Data
126-
*
127-
* @param exifOrientation ExifInterface.ORIENTATION_* representation of the rotation
128-
* @return the rotation in degrees
129-
*/
130-
private int getRoationDegrees(int exifOrientation){
131-
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
132-
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
133-
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
134-
return 0;
135-
}
136-
137-
/**
138-
* Gets the image rotation from the image EXIF Data
139-
*
140-
* @param uriString the URI of the image to get the rotation for
141-
* @return ExifInterface.ORIENTATION_* representation of the rotation
142-
*/
143-
private int getRotation(String uriString){
144-
try {
145-
ExifInterface exif = new ExifInterface(uriString);
146-
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
147-
} catch (IOException e) {
148-
return ExifInterface.ORIENTATION_NORMAL;
149-
}
150-
}
151-
15274
/**
15375
* Loads a Bitmap of the given android uri path
15476
*

src/ios/ImageResizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
#import <Photos/Photos.h>
33
@interface ImageResizer : CDVPlugin
44
- (void) resize:(CDVInvokedUrlCommand*)command;
5-
- (UIImage*) rotateImage:(UIImage*) image withRotation:(int) rotation;
65
@end

src/ios/ImageResizer.m

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,12 @@ - (void) resize:(CDVInvokedUrlCommand*)command
2929
NSString* fileName = [arguments objectForKey:@"fileName"];
3030

3131
BOOL asBase64 = [[arguments objectForKey:@"base64"] boolValue];
32-
BOOL fixRotation = [[arguments objectForKey:@"fixRotation"] boolValue];
3332

3433
// //Get the image from the path
3534
NSURL* imageURL = [NSURL URLWithString:imageUrlString];
3635

3736
sourceImage = [UIImage imageWithData: [NSData dataWithContentsOfURL: imageURL]];
38-
39-
int rotation = 0;
40-
41-
switch ([sourceImage imageOrientation]) {
42-
case UIImageOrientationUp:
43-
rotation = 0;
44-
break;
45-
case UIImageOrientationDown:
46-
rotation = 180;
47-
break;
48-
case UIImageOrientationLeft:
49-
rotation = 270;
50-
break;
51-
case UIImageOrientationRight:
52-
rotation = 90;
53-
break;
54-
default:
55-
break;
56-
}
57-
37+
5838
PHFetchResult *savedAssets = [PHAsset fetchAssetsWithLocalIdentifiers:@[fileName] options:nil];
5939
[savedAssets enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
6040
//this gets called for every asset from its localIdentifier you saved
@@ -107,10 +87,6 @@ - (void) resize:(CDVInvokedUrlCommand*)command
10787

10888
tempImage = UIGraphicsGetImageFromCurrentImageContext();
10989
NSLog(@"image resizer:%@", (tempImage ? @"image exsist" : @"null" ));
110-
111-
if(fixRotation){
112-
tempImage = [self rotateImage:tempImage withRotation:rotation];
113-
}
11490

11591
UIGraphicsEndImageContext();
11692
NSData *imageData = UIImageJPEGRepresentation(tempImage, [quality floatValue] / 100.0f );
@@ -143,26 +119,4 @@ - (void) resize:(CDVInvokedUrlCommand*)command
143119
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
144120
}
145121

146-
- (UIImage*) rotateImage:(UIImage*) image withRotation:(int) rotation{
147-
CGFloat rot = rotation * M_PI / 180;
148-
149-
// Calculate Destination Size
150-
CGAffineTransform t = CGAffineTransformMakeRotation(rot);
151-
CGRect sizeRect = (CGRect) {.size = image.size};
152-
CGRect destRect = CGRectApplyAffineTransform(sizeRect, t);
153-
CGSize destinationSize = destRect.size;
154-
155-
// Draw image
156-
UIGraphicsBeginImageContext(destinationSize);
157-
CGContextRef context = UIGraphicsGetCurrentContext();
158-
CGContextTranslateCTM(context, destinationSize.width / 2.0f, destinationSize.height / 2.0f);
159-
CGContextRotateCTM(context, rot);
160-
[image drawInRect:CGRectMake(-image.size.width / 2.0f, -image.size.height / 2.0f, image.size.width, image.size.height)];
161-
162-
// Save image
163-
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
164-
UIGraphicsEndImageContext();
165-
return newImage;
166-
}
167-
168122
@end

0 commit comments

Comments
 (0)