Skip to content

Commit

Permalink
Merge pull request #6 from spoonconsulting/bitmap-null-check
Browse files Browse the repository at this point in the history
Bitmap null check
  • Loading branch information
HashirRajah authored Oct 1, 2024
2 parents 3dc41c9 + a661474 commit 040a5bb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="@spoonconsulting/cordova-plugin-thumbnail" version="1.0.3">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="@spoonconsulting/cordova-plugin-thumbnail" version="1.0.4">
<name>Thumbnail</name>
<description>Cordova Thumbnail Plugin</description>
<license>Apache 2.0</license>
Expand All @@ -12,6 +12,9 @@
<dependency id="cordova-plugin-file"/>

<platform name="android">
<framework src="com.fasterxml.jackson.core:jackson-core:+" />
<framework src="com.fasterxml.jackson.core:jackson-databind:+" />

<config-file target="res/xml/config.xml" parent="/*">
<feature name="Thumbnails">
<param name="android-package" value="com.cordova.plugin.thumbnail.ThumbnailsCordovaPlugin"/>
Expand Down
12 changes: 10 additions & 2 deletions src/android/Thumbnails.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/android/ThumbnailsCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 040a5bb

Please sign in to comment.