cordova-plugin-image-resizer icon indicating copy to clipboard operation
cordova-plugin-image-resizer copied to clipboard

displaying resized image

Open juszczec opened this issue 8 years ago • 6 comments

i have a question about displaying a resized image

i'm doing this with cordova on android.

cordova has a property called cordova.file.applicationDirectory that maps to the uri file:///android_asset/

thru trial and error i have discovered android_asset contains the standard cordova directory named www

i have placed sample.jpg in www and referenced it in the following example

   var options = {
                    uri: cordova.file.applicationDirectory + "www/sample.jpg",
                    folderName: "www",
                    filename: "resized.jpg",
                    quality: 90,
                    width: 32,
                    height: 32};

    window.ImageResizer.resize(options,
                               function(image) {
                                   alert("resize success");
			       var htmlToAppend = '<img src="www/resized.jpg" />';
			       $('#scaled').append(htmlToAppend);
                               }, 
                               function() {
                                   alert("FAIL");
                               });

however, when this runs, no image displays.

what is the recommended way to reference a resized image?

juszczec avatar Mar 28 '17 01:03 juszczec

I have to take a closer look on that

JoschkaSchulz avatar Mar 28 '17 08:03 JoschkaSchulz

When I changed the first callback to:

                               function(image) {
                                   alert("resize success");
			       var htmlToAppend = '<img src="'+image+'" />';
			       $('#scaled').append(htmlToAppend);
                               }

I got a scaled image to appear.

So, the image is scaling but folderName and filename appear to be ignored.

juszczec avatar Mar 28 '17 23:03 juszczec

hrm okay, I think I have some time on Friday to look on all the Issus in that Repo. :)

JoschkaSchulz avatar Mar 29 '17 07:03 JoschkaSchulz

Hello, It doesn't work on iOS that way. I tried to put in Image src the path received from the success callback, but it didn't work. Ended up with adding an option 'base64', which, if set to true, results in returning base64 string image representation. @JoschkaSchulz if you're ok with this approach, I can submit a PR.

EternallLight avatar Nov 14 '17 10:11 EternallLight

@EternallLight it would be nice :)

JoschkaSchulz avatar Nov 14 '17 15:11 JoschkaSchulz

Here you go!

EternallLight avatar Nov 14 '17 19:11 EternallLight