RaananW / PhoneGap-Image-Resizer

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

iOS crashes no matter what i change #27

Open rares-lupascu opened 8 years ago

rares-lupascu commented 8 years ago

hi

i use the following code in a phonegap app ... android works fine ... but iOS keeps crashing not matter what params i change

this is my code:

var filePath = window.rootFS.toURL() + window.mainDirectory + "/" + $scope.sCurrentDate + "/" + fileName;
var options = {
  format: ImageResizer.FORMAT_JPG,
  resizeType: ImageResizer.RESIZE_TYPE_PIXEL,
  directory: window.rootFS.toURL() + window.mainDirectory + "/" + $scope.sCurrentDate + "/",
  quality: 90,
  pixelDensity: false,
  storeImage: true,
  filename: fileName.substring(0, fileName.lastIndexOf('.')) + "_thumb.jpg",
  photoAlbum: true
};
window.imageResizer.resizeImage(function(image, height, width) {
  console.log(image);
}, function(data) {
  console.log(data);
  alert('failed' + JSON.stringify(data));
}, filePath, 500, 250, options);
RaananW commented 8 years ago

Is there an exception shown? something to work with? Would be great to know what the actual error is. Also iOS version would help as well.

Just a note, when using the photo album option, the directory and filename are being ignored.

My main problem is, just with the rest of the iOS tickets, I currently have no iPhone or mac to test it with. I will try arranging one next week.

rares-lupascu commented 8 years ago

if u can imagine i have the same pb :) .... i am using gapdebug to debug the app but nothing is returned .. the app simply closes ... btw ... the photoalbum is the last one i tried ... before that ... i only tried juggling with storeImage and directory and imageData

ok so what i can tell u is that i tested on iOS 9.1 and that it always executes the failure function with not data returned (null)

quick question: do the imageData and directory url need to have a specific format for iOS?

RaananW commented 8 years ago

The image data is either a URL or a base64 string. You will then have to set the imageDataType in the options (default is URL). I would give base64 a try, just to see if it is the reason for the error.

Directory is actually always ignored with iOS (on the readme's iOS quirks) . Try the simple example from the readme:

window.imageResizer.resizeImage(
   function(data) { 
     var image = document.getElementById('myImage');
     image.src = "data:image/jpeg;base64," + data.imageData; 
   }, function (error) {
     console.log("Error : \r\n" + error);
   }, imageDataInBase64, 0.5, 0.5, {
      resizeType: ImageResizer.RESIZE_TYPE_FACTOR,
      imageDataType: ImageResizer.IMAGE_DATA_TYPE_BASE64,
      format: ImageResizer.FORMAT_JPG
   }
);

If it is working, something is either wrong with the URL or the plugin itself when used with the URL option. If it doesn't work, it might be a problem with the iOS version (have to admit, never really tested with iOS 9, they might have changed something) or the plugin's implementation.

rares-lupascu commented 8 years ago

i will try tomorrow and post the results ... thanks :)

rares-lupascu commented 8 years ago

hey ... i am really going insane here i tried every possible combination ... my pb is i can only use a url to feed the plugin ... i cannot feed it base64 - or i do not know how ... my scenario is like this:

RaananW commented 8 years ago

Hmmm.... this is odd. I would hear about it already. You can use a canvas to export base64 (using toDataURL(). This might help - https://stackoverflow.com/questions/15760764/how-to-get-base64-encoded-data-from-html-image#15761420)

I am so sorry I can't really help. I will try getting a mac set up in the near future, but I really can't promise anything. If any of the people watching this wants to give a hand - please do. would be wonderful :)

Heshyo commented 8 years ago

@rarutu: I forked this repo quite some time ago and did a few things on the iOS side to make it work. You may want to check if it fixes things for you or not https://github.com/Sharinglabs/PhoneGap-Image-Resizer (note that the plugin ID is different).

RaananW commented 8 years ago

Not quite the reaction I was expecting.

You know, you could help an open source project by contributing. But that's just my opinion.

rares-lupascu commented 8 years ago

thank you @Heshyo :) really appreciate it RaanamW i really think you guys can merge the two branches :) i think @Heshyo will agree :)

RaananW commented 8 years ago

He could have done that already :) What he did, however, was direct you to a different (his) repo. I find it very interesting. Especially when the GitHub account is called "Sharinglabs".

I always accepted PRs, and am still accepting them.

rares-lupascu commented 8 years ago

uff ... can't really tell were to go from here :( btw ... i did exactly what you said "5 posts ago" ... created a 2d canvas with the desired size ... filled it with the image ... used a function to do dataURIToBlob ... and wrote the blob where i wanted ... worked on the first try :)

RaananW commented 8 years ago

Perfect :) So it is working. Generally speaking :)

I will check how I can solve the rest of the iOS bugs and update here.

rares-lupascu commented 8 years ago

haha :) yes ... be careful ... there are 2 separate things ...

u know what should be fun? if it works for you :)))

RaananW commented 8 years ago

Noted. I'll check that, together with 2 more iOS issues that are still open. Mac-as-a-service would be helpful :)

Edit - will you look at that... https://www.cforcrazy.com/daas/mocha/ :wink:

Heshyo commented 8 years ago

@RaananW: I never took the time to see what could be merged on not on your repo. It's still on my todo list. If the code from repo fixes @rarutu issue, then we could see what needs to be merged.

smajl commented 8 years ago

Resizing also crashes the application for me when I have storeImage: true :(

RaananW commented 8 years ago

Needs to be fixed. Issue is open (as all other iOS issues), I just found a mac-as-a-service with phonegap preinstalled, I will probably use that in the next few days to debug and fix things.

Heshyo commented 8 years ago

I rechecked my fork and there are conflicts with your repo on iOS. I'm no iOS developer so I'm having a hard time knowing if I should just overwrite your changes or try to be more intelligent. Also I did fix an issue I had on a 6.1.2 device, but I don't have such device anymore, so I'd rather not change my code as it looks like it's working on iOS 6, 7, 8 and 9.

For info I'm always using the following options when calling the plugin:

    var options = {
        directory: 'directoryToUse',
        filename: 'randomName.jpg',
        pixelDensity: false,
        quality: compression, // 75
        storeImage: true,
        resizeType: window.ImageResizer.RESIZE_TYPE_MAX_PIXEL
    };