From b7fa2f6ba2f19208e48c25768b3fae847127498e Mon Sep 17 00:00:00 2001 From: Mevin Dhunnooa Date: Wed, 19 Sep 2018 11:53:30 +0400 Subject: [PATCH 01/25] Fixed warning "thrown type FileNotFoundException has already been caught" com/cordova/plugin/thumbnail/Thumbnails.java:126: warning: unreachable catch clause } catch (IOException ex) { ^ thrown type FileNotFoundException has already been caught --- src/android/Thumbnails.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 31739d0..4ba04a1 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -123,9 +123,6 @@ public static Boolean saveBitmapToFile(Bitmap bitmap, String targetPath, Options bitmap.compress(guessImageType(targetPath), 90, os); } catch (FileNotFoundException ex) { throw new TargetPathNotFoundException(ex); - } catch (IOException ex) { - Log.e("Thumbnails.saveBitmapToFile()", "Error opening file stream:" + targetPath); - ex.printStackTrace(); } finally { if (os != null) { try { From b0215dd45461b4e03b45b171dbde14ca6a0e69e3 Mon Sep 17 00:00:00 2001 From: Mevin <17478561+mevinDhun@users.noreply.github.com> Date: Fri, 8 Feb 2019 14:15:45 +0400 Subject: [PATCH 02/25] force thumbnail generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The property with key kCGImageSourceCreateThumbnailFromImageAlways with a value of true means that any thumbnail image embedded in the image file is ignored and the image generated is from the full size image. If you don’t do this and the image file contains a thumbnail image then the max size you specify is ignored and you get the embedded thumbnail image, this is rarely what you want. --- src/ios/Thumbnail.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index 9f76ca0..db250de 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -94,7 +94,8 @@ + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPi NSDictionary *imageOptions = @{ (NSString const *)kCGImageSourceCreateThumbnailFromImageIfAbsent : (NSNumber const *)kCFBooleanTrue, (NSString const *)kCGImageSourceThumbnailMaxPixelSize : @(maxPixelSize), - (NSString const *)kCGImageSourceCreateThumbnailWithTransform : (NSNumber const *)kCFBooleanTrue + (NSString const *)kCGImageSourceCreateThumbnailWithTransform : (NSNumber const *)kCFBooleanTrue, + (NSString const *)kCGImageSourceCreateThumbnailFromImageAlways : (NSNumber const *)kCFBooleanTrue }; CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)imageOptions); CFRelease(imageSource); From afb225d02821866976705b9b87cc07c7e9200ffa Mon Sep 17 00:00:00 2001 From: Luc Boissaye Date: Thu, 6 Aug 2020 09:50:50 -0400 Subject: [PATCH 03/25] Create spoonconsulting version --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7279db8..8ae30e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "cordova-plugin-thumbnail", - "version": "1.0.0", + "name": "@spoonconsulting/cordova-plugin-thumbnail", + "version": "1.0.1", "description": "Image thumbnail generator for Cordova project", "cordova": { "id": "cordova-plugin-thumbnail", @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/almas/cordova-plugin-thumbnail.git" + "url": "git+https://github.com/spoonconsulting/cordova-plugin-thumbnail.git" }, "keywords": [ "thumbnail", @@ -19,12 +19,12 @@ "cordova-android", "cordova-ios" ], - "author": "Almas", + "author": "Almas & Spoonconsulting", "license": "Apache 2.0", "bugs": { - "url": "https://github.com/almas/cordova-plugin-thumbnail/issues" + "url": "https://github.com/spoonconsulting/cordova-plugin-thumbnail/issues" }, - "homepage": "https://github.com/almas/cordova-plugin-thumbnail#readme", + "homepage": "https://github.com/spoonconsulting/cordova-plugin-thumbnail#readme", "engines": { "cordovaDependencies": { "0.1.0": { From 0a5d58c39d8b52756879788f3e94b2b9f5d9e7f1 Mon Sep 17 00:00:00 2001 From: dinitri-ragoo Date: Fri, 26 Feb 2021 17:14:31 +0400 Subject: [PATCH 04/25] add correct plugin id --- package.json | 4 ++-- plugin.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8ae30e1..297edcb 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.1", + "version": "1.0.2", "description": "Image thumbnail generator for Cordova project", "cordova": { - "id": "cordova-plugin-thumbnail", + "id": "@spoonconsulting/cordova-plugin-thumbnail", "platforms": [ "ios", "android" diff --git a/plugin.xml b/plugin.xml index b66a9ba..7a3b62d 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Thumbnail Cordova Thumbnail Plugin Apache 2.0 From 5eb74ca9e10bebc6845213f9deeb7dbdd8343127 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 9 May 2023 12:57:58 +0400 Subject: [PATCH 05/25] create thumbnail with appropriate height and width --- src/ios/Thumbnail.m | 47 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index db250de..e7ee19f 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -85,25 +85,50 @@ + (void) thumbnail:(NSString *)imageURL size:(CGFloat)maxSize toURL:(NSString *) + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPixelSize { + NSData *data = [NSData dataWithContentsOfURL:URL]; + UIImage* image = [[UIImage alloc]initWithData:data]; CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)URL, NULL); + CGFloat scale = [[UIScreen mainScreen] scale]; // Get the screen scale + if(imageSource == NULL) { NSLog(@"Can not read from source: %@", URL); return NULL; } + + + CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + NSDictionary *properties = (NSDictionary*)CFBridgingRelease(props); - NSDictionary *imageOptions = @{ - (NSString const *)kCGImageSourceCreateThumbnailFromImageIfAbsent : (NSNumber const *)kCFBooleanTrue, - (NSString const *)kCGImageSourceThumbnailMaxPixelSize : @(maxPixelSize), - (NSString const *)kCGImageSourceCreateThumbnailWithTransform : (NSNumber const *)kCFBooleanTrue, - (NSString const *)kCGImageSourceCreateThumbnailFromImageAlways : (NSNumber const *)kCFBooleanTrue - }; - CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)imageOptions); - CFRelease(imageSource); + if (!properties) { + NSLog(@"No properties"); + } - UIImage *result = [[UIImage alloc] initWithCGImage:thumbnail]; - CGImageRelease(thumbnail); + double heightInPixel = [[properties objectForKey:@"PixelHeight"] doubleValue]; + double widthInPixel = [[properties objectForKey:@"PixelWidth"]doubleValue]; + NSNumber *orientation = [properties objectForKey:@"Orientation"]; + + double heightInPoint = heightInPixel / (double)(image.scale); + double widthInPoint = widthInPixel / (double)(image.scale); + + double ratio = MIN(widthInPoint/maxPixelSize, heightInPoint/maxPixelSize); + + double thumbnailHeight = (heightInPoint/ratio) / scale; + double thumbnailWidth = (widthInPoint/ratio) / scale; + + CGSize newSize; + if ([orientation isEqualToNumber:@6]) { + newSize = CGSizeMake(thumbnailHeight, thumbnailWidth); + } + else { + newSize = CGSizeMake(thumbnailWidth, thumbnailHeight); + } + + UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); + [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); - return result; + return newImage; } @end From 5afcb8ff10405ef2dd6e077fbaa9caf5765d9eb4 Mon Sep 17 00:00:00 2001 From: dinitri Date: Wed, 10 May 2023 15:02:12 +0400 Subject: [PATCH 06/25] use ios built-in function for thumbnail --- src/ios/Thumbnail.m | 54 +++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index e7ee19f..faeab2e 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -87,48 +87,24 @@ + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPi { NSData *data = [NSData dataWithContentsOfURL:URL]; UIImage* image = [[UIImage alloc]initWithData:data]; - CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)URL, NULL); - CGFloat scale = [[UIScreen mainScreen] scale]; // Get the screen scale - - if(imageSource == NULL) { - NSLog(@"Can not read from source: %@", URL); - return NULL; - } - - - CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - NSDictionary *properties = (NSDictionary*)CFBridgingRelease(props); - - if (!properties) { - NSLog(@"No properties"); - } - - double heightInPixel = [[properties objectForKey:@"PixelHeight"] doubleValue]; - double widthInPixel = [[properties objectForKey:@"PixelWidth"]doubleValue]; - NSNumber *orientation = [properties objectForKey:@"Orientation"]; - double heightInPoint = heightInPixel / (double)(image.scale); - double widthInPoint = widthInPixel / (double)(image.scale); + double maxPointSize = maxPixelSize / (double) (image.scale); + double ratio = MIN(image.size.width/maxPointSize, image.size.height/maxPointSize); + double thumbnailHeight = (image.size.height/ratio) / image.scale; + double thumbnailWidth = (image.size.width/ratio) / image.scale; + CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); - double ratio = MIN(widthInPoint/maxPixelSize, heightInPoint/maxPixelSize); - - double thumbnailHeight = (heightInPoint/ratio) / scale; - double thumbnailWidth = (widthInPoint/ratio) / scale; - - CGSize newSize; - if ([orientation isEqualToNumber:@6]) { - newSize = CGSizeMake(thumbnailHeight, thumbnailWidth); - } - else { - newSize = CGSizeMake(thumbnailWidth, thumbnailHeight); + if (@available(iOS 15.0, *)) { + UIImage *newImage = [image imageByPreparingThumbnailOfSize: thumbnailSize]; + return newImage; + } else { + // Fallback on earlier versions + UIGraphicsBeginImageContextWithOptions(thumbnailSize, false, 0.0); + [image drawInRect:CGRectMake(0, 0, thumbnailSize.width, thumbnailSize.height)]; + UIImage *thumbnailImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return thumbnailImage; } - - UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); - [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; - UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return newImage; } @end From b4c890db469cc9f5214fcece2786f848e73427fc Mon Sep 17 00:00:00 2001 From: dinitri Date: Wed, 10 May 2023 16:33:17 +0400 Subject: [PATCH 07/25] use correct when using uiimage and uigraphic --- src/ios/Thumbnail.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index faeab2e..7e97338 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -87,18 +87,20 @@ + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPi { NSData *data = [NSData dataWithContentsOfURL:URL]; UIImage* image = [[UIImage alloc]initWithData:data]; - + double maxPointSize = maxPixelSize / (double) (image.scale); double ratio = MIN(image.size.width/maxPointSize, image.size.height/maxPointSize); - double thumbnailHeight = (image.size.height/ratio) / image.scale; - double thumbnailWidth = (image.size.width/ratio) / image.scale; - CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); if (@available(iOS 15.0, *)) { + double thumbnailHeight = (image.size.height/ratio) / image.scale; + double thumbnailWidth = (image.size.width/ratio) / image.scale; + CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); UIImage *newImage = [image imageByPreparingThumbnailOfSize: thumbnailSize]; return newImage; } else { - // Fallback on earlier versions + double thumbnailHeight = (image.size.height/ratio) / UIScreen.mainScreen.scale; + double thumbnailWidth = (image.size.width/ratio) / UIScreen.mainScreen.scale; + CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); UIGraphicsBeginImageContextWithOptions(thumbnailSize, false, 0.0); [image drawInRect:CGRectMake(0, 0, thumbnailSize.width, thumbnailSize.height)]; UIImage *thumbnailImage = UIGraphicsGetImageFromCurrentImageContext(); From 37f30abf17227feb770bf0bf82c6bb8bcdce8475 Mon Sep 17 00:00:00 2001 From: dinitri Date: Thu, 11 May 2023 16:47:16 +0400 Subject: [PATCH 08/25] fix landscape ratio --- src/android/Thumbnails.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 4ba04a1..658542a 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -47,7 +47,12 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOExc int oWidth = bitmap.getWidth(); int oHeight = bitmap.getHeight(); - float ratio = Math.min(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); + float ratio; + if (orientation != 1) { + ratio = Math.min(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); + } else { + ratio = Math.max(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); + } if (ratio > 1) { int width = (int) (oWidth / ratio); From 69cf4bd43e29d10a2c1249e0cd0aca0f95e4aa11 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 12 May 2023 11:15:17 +0400 Subject: [PATCH 09/25] move orientation declaration --- src/android/Thumbnails.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 658542a..96ef608 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -46,8 +46,9 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOExc long begin = System.currentTimeMillis(); int oWidth = bitmap.getWidth(); int oHeight = bitmap.getHeight(); - float ratio; + ExifInterface exif = new ExifInterface(thumbnailOptions.sourcePath); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation != 1) { ratio = Math.min(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); } else { @@ -60,8 +61,6 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOExc bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height); } - ExifInterface exif = new ExifInterface(thumbnailOptions.sourcePath); - int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation != 1) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), getRotationMatrix(orientation), true); } From 6204d4f66c0a48e53feb95637c43fb24ae59044d Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 12 May 2023 14:45:24 +0400 Subject: [PATCH 10/25] fix orientation ratio ios --- src/ios/Thumbnail.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index 7e97338..ff8cba5 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -89,7 +89,12 @@ + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPi UIImage* image = [[UIImage alloc]initWithData:data]; double maxPointSize = maxPixelSize / (double) (image.scale); - double ratio = MIN(image.size.width/maxPointSize, image.size.height/maxPointSize); + double ratio; + if ((image.size.width / image.size.height) > 1) { + ratio = MAX(image.size.width/maxPointSize, image.size.height/maxPointSize); + } else { + ratio = MIN(image.size.width/maxPointSize, image.size.height/maxPointSize); + } if (@available(iOS 15.0, *)) { double thumbnailHeight = (image.size.height/ratio) / image.scale; @@ -155,6 +160,12 @@ - (CGFloat) getMaxSize: (CDVInvokedUrlCommand *) command { if ([command.arguments count] == 2) { maxPixelSize = [command.arguments objectAtIndex:1]; } else { + await this.save(); + await (await this.getBatch()).computeProgress(); + return; + } else { + Logger.log({ + eventLabel: "Upload failed", maxPixelSize = [command.arguments objectAtIndex:2]; } return [maxPixelSize floatValue]; From 9a7fe03b44e96d33e22325b9fc9882fd3fff50a7 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 12 May 2023 14:47:59 +0400 Subject: [PATCH 11/25] remove unused code --- src/ios/Thumbnail.m | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index ff8cba5..400e7b0 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -160,12 +160,6 @@ - (CGFloat) getMaxSize: (CDVInvokedUrlCommand *) command { if ([command.arguments count] == 2) { maxPixelSize = [command.arguments objectAtIndex:1]; } else { - await this.save(); - await (await this.getBatch()).computeProgress(); - return; - } else { - Logger.log({ - eventLabel: "Upload failed", maxPixelSize = [command.arguments objectAtIndex:2]; } return [maxPixelSize floatValue]; From 0f7400065c32333263cecf57322dafeae524cf4d Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 16 May 2023 12:31:44 +0400 Subject: [PATCH 12/25] revert changes from android thumbnail plugin --- src/android/Thumbnails.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 96ef608..947b1e7 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -46,14 +46,8 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOExc long begin = System.currentTimeMillis(); int oWidth = bitmap.getWidth(); int oHeight = bitmap.getHeight(); - float ratio; - ExifInterface exif = new ExifInterface(thumbnailOptions.sourcePath); - int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); - if (orientation != 1) { - ratio = Math.min(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); - } else { - ratio = Math.max(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); - } + + float ratio = Math.min(oWidth * 1.0f / thumbnailOptions.maxPixelSize, oHeight * 1.0f / thumbnailOptions.maxPixelSize); if (ratio > 1) { int width = (int) (oWidth / ratio); @@ -61,6 +55,8 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOExc bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height); } + ExifInterface exif = new ExifInterface(thumbnailOptions.sourcePath); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation != 1) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), getRotationMatrix(orientation), true); } @@ -161,4 +157,4 @@ public static class Options { public Options() { } } -} +} \ No newline at end of file From 72499c9c59fed35e52ea09d92cb66f21e8bd645f Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 22 May 2023 12:43:47 +0400 Subject: [PATCH 13/25] add eof line --- src/android/Thumbnails.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 947b1e7..4ba04a1 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -157,4 +157,4 @@ public static class Options { public Options() { } } -} \ No newline at end of file +} From ad0df4bf98404904a6a41031f454acbaaba0697f Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 5 Jun 2023 11:12:27 +0400 Subject: [PATCH 14/25] code refactoring --- src/ios/Thumbnail.m | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index 400e7b0..77b8d1e 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -86,26 +86,28 @@ + (void) thumbnail:(NSString *)imageURL size:(CGFloat)maxSize toURL:(NSString *) + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPixelSize { NSData *data = [NSData dataWithContentsOfURL:URL]; - UIImage* image = [[UIImage alloc]initWithData:data]; - + UIImage* image = [[UIImage alloc] initWithData:data]; + double thumbnailHeight; + double thumbnailWidth; + CGSize thumbnailSize; double maxPointSize = maxPixelSize / (double) (image.scale); double ratio; + if ((image.size.width / image.size.height) > 1) { - ratio = MAX(image.size.width/maxPointSize, image.size.height/maxPointSize); + ratio = MAX(image.size.width / maxPointSize, image.size.height / maxPointSize); } else { - ratio = MIN(image.size.width/maxPointSize, image.size.height/maxPointSize); + ratio = MIN(image.size.width / maxPointSize, image.size.height / maxPointSize); } if (@available(iOS 15.0, *)) { - double thumbnailHeight = (image.size.height/ratio) / image.scale; - double thumbnailWidth = (image.size.width/ratio) / image.scale; - CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); - UIImage *newImage = [image imageByPreparingThumbnailOfSize: thumbnailSize]; - return newImage; + thumbnailHeight = (image.size.height / ratio) / image.scale; + thumbnailWidth = (image.size.width / ratio) / image.scale; + thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); + return [image imageByPreparingThumbnailOfSize: thumbnailSize]; } else { - double thumbnailHeight = (image.size.height/ratio) / UIScreen.mainScreen.scale; - double thumbnailWidth = (image.size.width/ratio) / UIScreen.mainScreen.scale; - CGSize thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); + thumbnailHeight = (image.size.height / ratio) / UIScreen.mainScreen.scale; + thumbnailWidth = (image.size.width / ratio) / UIScreen.mainScreen.scale; + thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight); UIGraphicsBeginImageContextWithOptions(thumbnailSize, false, 0.0); [image drawInRect:CGRectMake(0, 0, thumbnailSize.width, thumbnailSize.height)]; UIImage *thumbnailImage = UIGraphicsGetImageFromCurrentImageContext(); From 1d5c24d957ed5062a6dfc361a76036d87e64abc1 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 9 Jun 2023 10:29:47 +0400 Subject: [PATCH 15/25] refactoring --- src/ios/Thumbnail.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/Thumbnail.m b/src/ios/Thumbnail.m index 77b8d1e..5e396f1 100755 --- a/src/ios/Thumbnail.m +++ b/src/ios/Thumbnail.m @@ -91,8 +91,8 @@ + (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPi double thumbnailWidth; CGSize thumbnailSize; double maxPointSize = maxPixelSize / (double) (image.scale); + double ratio; - if ((image.size.width / image.size.height) > 1) { ratio = MAX(image.size.width / maxPointSize, image.size.height / maxPointSize); } else { From 5679d7fbe3d1a6cf3f3b265714fa4557bc84f9f0 Mon Sep 17 00:00:00 2001 From: Dinitri Ragoo <42667690+dinitri@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:42:53 +0400 Subject: [PATCH 16/25] Create npm-publish.yml --- .github/workflows/npm-publish.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..d526652 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,13 @@ +name: Node.js Package +on: push +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: bahmutov/npm-install@v1 + - id: publish + uses: JS-DevTools/npm-publish@v1 + with: + token: ${{ secrets.npm_token }} + From baba057925f9612e6bd8e27323bbf2dfad11e2ec Mon Sep 17 00:00:00 2001 From: dinitri Date: Fri, 9 Jun 2023 14:44:42 +0400 Subject: [PATCH 17/25] create package-lock --- package-lock.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..dee29fb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,20 @@ +{ + "name": "@spoonconsulting/cordova-plugin-thumbnail", + "version": "1.0.2", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@spoonconsulting/cordova-plugin-thumbnail", + "version": "1.0.2", + "license": "Apache 2.0", + "engines": { + "cordovaDependencies": { + "0.1.0": { + "cordova-plugin-file": "> 6.0.0" + } + } + } + } + } +} From eda77b8ba78a1a74780d2c29f46a02819641f273 Mon Sep 17 00:00:00 2001 From: dinitri Date: Fri, 9 Jun 2023 14:49:47 +0400 Subject: [PATCH 18/25] version bump 1.0.3 --- package-lock.json | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index dee29fb..62eb6f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.2", + "version": "1.0.3", "license": "Apache 2.0", "engines": { "cordovaDependencies": { diff --git a/package.json b/package.json index 297edcb..2d5b9cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.2", + "version": "1.0.3", "description": "Image thumbnail generator for Cordova project", "cordova": { "id": "@spoonconsulting/cordova-plugin-thumbnail", diff --git a/plugin.xml b/plugin.xml index 7a3b62d..f2f8368 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Thumbnail Cordova Thumbnail Plugin Apache 2.0 From 91392e2b742b7da5826c13797e610cf0acc36753 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 15:02:33 +0400 Subject: [PATCH 19/25] Add jackson --- plugin.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin.xml b/plugin.xml index f2f8368..98a16bb 100755 --- a/plugin.xml +++ b/plugin.xml @@ -12,6 +12,9 @@ + + + From ab0681535a2cca47761e4ce67c2d199ee32223c7 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 15:02:42 +0400 Subject: [PATCH 20/25] Import jackson --- src/android/Thumbnails.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 4ba04a1..8532255 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -16,10 +16,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; public class Thumbnails { - public static void thumbnail(Options thumbnailOptions) throws IOException { + public static void thumbnail(Options thumbnailOptions) throws Exception { long begin = System.currentTimeMillis(); Bitmap bitmap = thumbnailSmallImage(thumbnailOptions); @@ -37,7 +39,7 @@ public static void thumbnail(Options thumbnailOptions) throws IOException { bitmap = null; } - private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOException { + private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws Exception { BitmapFactory.Options options = calculateImageSize(thumbnailOptions.sourcePath); options.inJustDecodeBounds = false; From 6b2eedf0fcb9e36f10b7dd4a0108a34ba99f85a2 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 15:04:42 +0400 Subject: [PATCH 21/25] Add null check --- src/android/Thumbnails.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 8532255..503bb06 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -45,6 +45,12 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws Excep options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeFile(thumbnailOptions.sourcePath, options); + if (bitmap == null) { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String optionsJSON = ow.writeValueAsString(options); + throw new Exception("Could not decode file into bitmap object { sourcePath: " + thumbnailOptions.sourcePath + " options: " + optionsJSON + " }"); + } + long begin = System.currentTimeMillis(); int oWidth = bitmap.getWidth(); int oHeight = bitmap.getHeight(); From 5cb44dc97c3443b34b4a90e50396f08301e8b903 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 16:10:19 +0400 Subject: [PATCH 22/25] Latest jackson version --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 98a16bb..1134055 100755 --- a/plugin.xml +++ b/plugin.xml @@ -12,8 +12,8 @@ - - + + From 060c2c42aeb30aa3aa86672db5060b5e7937ce82 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 16:19:11 +0400 Subject: [PATCH 23/25] Remove jackson for test --- plugin.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 1134055..f637e5c 100755 --- a/plugin.xml +++ b/plugin.xml @@ -12,8 +12,6 @@ - - From 2d458ee3dea9af2997533aab30e96d5e7683d6c1 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Tue, 24 Sep 2024 16:24:38 +0400 Subject: [PATCH 24/25] Add jackson --- plugin.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin.xml b/plugin.xml index f637e5c..cb9dff2 100755 --- a/plugin.xml +++ b/plugin.xml @@ -12,6 +12,8 @@ + + From 2b8ebb0319462abe305aa1a8631875bf590b528f Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Wed, 25 Sep 2024 10:18:33 +0400 Subject: [PATCH 25/25] testing --- plugin.xml | 2 -- src/android/Thumbnails.java | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plugin.xml b/plugin.xml index cb9dff2..f637e5c 100755 --- a/plugin.xml +++ b/plugin.xml @@ -12,8 +12,6 @@ - - diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 503bb06..cb65cc4 100755 --- a/src/android/Thumbnails.java +++ b/src/android/Thumbnails.java @@ -16,8 +16,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; public class Thumbnails { @@ -46,9 +44,7 @@ private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws Excep Bitmap bitmap = BitmapFactory.decodeFile(thumbnailOptions.sourcePath, options); if (bitmap == null) { - ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); - String optionsJSON = ow.writeValueAsString(options); - throw new Exception("Could not decode file into bitmap object { sourcePath: " + thumbnailOptions.sourcePath + " options: " + optionsJSON + " }"); + throw new Exception("Could not decode file into bitmap object { sourcePath: " + thumbnailOptions.sourcePath + " options: }"); } long begin = System.currentTimeMillis();