RaananW / PhoneGap-Image-Resizer

Providing an image resizer plugin for phonegap projects on both Android and iOS
93 stars 89 forks source link

Resizing an image with options.storeImage = true is not working #13

Closed razwasserstein closed 9 years ago

razwasserstein commented 9 years ago

Hi,

When resizing an image with a file uri as a result (and not base64) the app CRASHES. I have tried numerous options for the options.directory, and options.filename.. none worked. Eventually the result was the same - CRASH.

What am I doing wrong? Is there a sample of a file uri as a result somewhere?

Thanks, Doron

RaananW commented 9 years ago

Hi Doron,

I am currently not maintaining the code. I will find the time in the near future to update everything and make sure this plugin can be used with the newest phonegap/cordova version. I keep this issue open and will update here as soon as I made some progress.

Best, Raanan

RaananW commented 9 years ago

BTW - I believe the latest pull request solved this problem, please let me know if that was the problem!

Heshyo commented 9 years ago

I tried the latest version on Android and it works perfectly with storeImage = true. I pass a native URL as argument (ie something like file:///storage/sdcard0/projectName/img/2015/01/06/imgName.jpg) I do have one issue on Android with the default values though: In imageresize.js:

storeImage: (typeof options.storeImage !== "undefined") ? options.storeImage : 0,
pixelDensity: (typeof options.pixelDensity !== "undefined") ? options.pixelDensity : 1,

In ImageResizePlugin.java

if (params.getBoolean("storeImage")) {}
if (params.getBoolean("pixelDensity")) {}

It's complaining about not being able to convert 0 or 1 into a boolean. I fixed it by specifying true of false for both options. I don't know about iOS, but it'd be best to have correct default values.

tslater commented 9 years ago

I have the same issue... it should be true/false instead of 0/1, right?

tslater commented 9 years ago

changed them from

    var params = {
        data: imageData,
        width: width ? width : 0,
        height: height ? height : 0,
        format: options.format ? options.format : ImageResizer.FORMAT_JPG,
        imageDataType: options.imageType ? options.imageType : ImageResizer.IMAGE_DATA_TYPE_URL,
        resizeType: options.resizeType ? options.resizeType : ImageResizer.RESIZE_TYPE_MAX_PIXEL,
        quality: options.quality ? options.quality : 75,
        storeImage: (typeof options.storeImage !== "undefined") ? options.storeImage : 0,
        pixelDensity: (typeof options.pixelDensity !== "undefined") ? options.pixelDensity : 1,
        directory: options.directory ? options.directory : "",
        filename: options.filename ? options.filename : "",
        photoAlbum: (typeof options.photoAlbum !== "undefined") ? options.photoAlbum : 0
    };

to

    var params = {
        data: imageData,
        width: width ? width : 0,
        height: height ? height : 0,
        format: options.format ? options.format : ImageResizer.FORMAT_JPG,
        imageDataType: options.imageType ? options.imageType : ImageResizer.IMAGE_DATA_TYPE_URL,
        resizeType: options.resizeType ? options.resizeType : ImageResizer.RESIZE_TYPE_MAX_PIXEL,
        quality: options.quality ? options.quality : 75,
        storeImage: (typeof options.storeImage !== "undefined") ? options.storeImage : false,
        pixelDensity: (typeof options.pixelDensity !== "undefined") ? options.pixelDensity : true,
        directory: options.directory ? options.directory : "",
        filename: options.filename ? options.filename : "",
        photoAlbum: (typeof options.photoAlbum !== "undefined") ? options.photoAlbum : false
    };

and it seems to be working well.

before that I was getting Value 1 at pixelDensity of type java.lang.Integer cannot be converted to boolean errors on android. I haven't tested iOS yet.

RaananW commented 9 years ago

I was under the impression that the last pull twist actually fixed it. I still haven't got the chance to test it thoroughly. Sadly other things on the agenda keep me occupied :-)

Heshyo commented 9 years ago

Yes using a boolean should work on iOS too:

bool storeImage = [[options objectForKey:@"storeImage"] boolValue];
bool accountForPixelDensity = [[options objectForKey:@"pixelDensity"] boolValue];

@tslater if you test on iOS please tell us if the rest works, because I had to modify some things for the plugin to work.

RaananW commented 9 years ago

I have updated the js file to send boolean values instead of numbers - https://github.com/RaananW/PhoneGap-Image-Resizer/commit/0b4fa1ec98ffa75371a5dbb3cb091c4908307e09 Should be working correctly now.