diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1c9b701 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## [1.0.4](https://github.com/spoonconsulting/cordova-plugin-thumbnail/compare/1.0.3...1.0.4) (2024-10-01) +* **Android:** Return more informative error if BitmapFactory.decodeFile() returns null diff --git a/package-lock.json b/package-lock.json index 62eb6f6..0f4cee2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.3", + "version": "1.0.4", "license": "Apache 2.0", "engines": { "cordovaDependencies": { diff --git a/package.json b/package.json index 2d5b9cd..7a531bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-thumbnail", - "version": "1.0.3", + "version": "1.0.4", "description": "Image thumbnail generator for Cordova project", "cordova": { "id": "@spoonconsulting/cordova-plugin-thumbnail", diff --git a/plugin.xml b/plugin.xml index f2f8368..6bee36e 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Thumbnail Cordova Thumbnail Plugin Apache 2.0 @@ -12,6 +12,9 @@ + + + diff --git a/src/android/Thumbnails.java b/src/android/Thumbnails.java index 4ba04a1..29270f5 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,12 +39,18 @@ 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; Bitmap bitmap = BitmapFactory.decodeFile(thumbnailOptions.sourcePath, options); + if (bitmap == null) { + ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String optionsJSON = objectWriter.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(); diff --git a/src/android/ThumbnailsCordovaPlugin.java b/src/android/ThumbnailsCordovaPlugin.java index b848a0c..6bc0d2c 100755 --- a/src/android/ThumbnailsCordovaPlugin.java +++ b/src/android/ThumbnailsCordovaPlugin.java @@ -64,7 +64,8 @@ public void run() { if(!sourceFile.exists()){ callbackContext.error("The image file does not exist at path: " + options.sourcePath ); throw new IOException(String.format("The image file does not exist")); - } else if(!targetFile.exists()) { + } + if(!targetFile.exists()) { targetFile.getParentFile().mkdirs(); targetFile.createNewFile(); }