terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 295 forks source link

The code takes ~15 seconds to run #34

Closed kartagis closed 7 years ago

kartagis commented 7 years ago
var doUIChanges = function(library) {
  library.forEach(function(libraryItem) {
      $("#gallery").css("display", "none");
      image = "<img height='100px' width='100px' src='"+libraryItem.thumbnailURL+"' style='margin: 5px' />";
      $(image).appendTo(document.body);
  });
};
$("#gallery").on("click", function() {
  cordova.plugins.photoLibrary.getLibrary().then(doUIChanges);
});

Hello, I found this plugin, hoping to create my own grid with checkboxes on selected images and so on, but why would it take this long?

viskin commented 7 years ago

@arberK My previous comment was not exact. There were caching in getLibrary. Instruments showed it takes time. I removed image cache stuff completely. There should be a large performance improvement (I've got somewhere x3 faster).

arberkryeziu commented 7 years ago

now its working great. very fast, immediate results. from around 4000 photos in my library, around 200 photos are missing in results, but I dont know if thats a problem of this plugin. Maybe it has something to do with the photos synchronized in icloud or cached photos. However, i like the results now. Im using the plugin from github.

kartagis commented 7 years ago

Hello, Now I'd like some support. I am using getThumbnail as seen below, but I'm not able to add images to the DOM (they show up as 404s).

document.addEventListener("deviceready", function() {
  cordova.plugins.photoLibrary.getLibrary(function(res){
    var library=res.library;
    library.forEach(function(libraryItem){
      cordova.plugins.photoLibrary.getThumbnail(libraryItem,function(tb){
        image = "<div class='imgHolder'><img height='100px' class='img' width='100px' src='"+tb+"' style='margin: 5px' /></div>";
        $(image).appendTo($("#images"));
      })
    })
  })
});

I tried JSON.stringify on tb as well in order to find the properties, but they came up empty. @arberK what is the code that you used?

viskin commented 7 years ago

@arberK Good. Still, in my app the results are not immediate at all, it takes few seconds. So, chunks are relevant. I will prepare a demo app soon, as API of the plugin is stable now.

@kartagis getThumbnail is for special case when you need the image as Blob object. You don't need it here. In simple case (without optimization with chunks) it should look like this:

document.addEventListener("deviceready", function() {
  cordova.plugins.photoLibrary.getLibrary(function(res){
    var library=res.library;
    library.forEach(function(libraryItem){
        image = "<div class='imgHolder'><img height='100px' class='img' width='100px' src='"+libraryItem.thumbnailURL+"' style='margin: 5px' /></div>";
        $(image).appendTo($("#images"));
      })
  })
});
kartagis commented 7 years ago

What if I also wanted base64? thumbnailURL doesn't seem to provide that. 21 Şub 2017 Sal, saat 10:36 tarihinde viskin notifications@github.com şunu yazdı:

@arberK https://github.com/arberK Good. Still, in my app the results are not immediate at all, it takes few seconds. So, chunks are relevant. I will prepare a demo app soon, as API of the plugin is stable now.

@kartagis https://github.com/kartagis getThumbnail is for special case when you need the image as Blob object. You don't need it here. In simple case (without optimization with chunks) it should look like this:

document.addEventListener("deviceready", function() { cordova.plugins.photoLibrary.getLibrary(function(res){ var library=res.library; library.forEach(function(libraryItem){ image = "

"; $(image).appendTo($("#images")); }) }) });

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/terikon/cordova-plugin-photo-library/issues/34#issuecomment-281266914, or mute the thread https://github.com/notifications/unsubscribe-auth/ABiHXv6h2fsuLKf07EKU_YlFYeY4pLUYks5repPwgaJpZM4Lo5JO .

viskin commented 7 years ago

Well, if you need base64 for some reason, then yes, you can use getThumbnail. Do like explained here:

cordova.plugins.photoLibrary.getThumbnail(libraryItem, function(blob){
  var dataURI;
  var reader = new FileReader();
  reader.onload = function(){
    // here you'll call what to do with the base64 string result
    dataURI = this.result;
    console.log(dataURI);
    };
  reader.readAsDataURL(blob);
});

Just curious, why do you need base64?

kartagis commented 7 years ago

The API has been configured to accept base64. 21 Şub 2017 Sal, saat 13:32 tarihinde viskin notifications@github.com şunu yazdı:

Well, if you need base64 for some reason, then yes, you can use getThumbnail. Do like explained here http://stackoverflow.com/a/37130139/1691132:

cordova.plugins.photoLibrary.getThumbnail(libraryItem, function(blob){ var dataURI; var reader = new FileReader(); reader.onload = function(){ // here you'll call what to do with the base64 string result dataURI = this.result; console.log(dataURI); }; reader.readAsDataURL(blob); });

Just curious, why do you need base64?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/terikon/cordova-plugin-photo-library/issues/34#issuecomment-281305109, or mute the thread https://github.com/notifications/unsubscribe-auth/ABiHXiBvJiY1YJvndrRlWjVktHwnXf1vks5rer0wgaJpZM4Lo5JO .

viskin commented 7 years ago

@kartagis I added photo-library-demo-jquery. Removed the MegaList. It seems problematic. The simplest implementation works pretty fast.