meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.55k stars 404 forks source link

Multiple images by classname #164

Closed lajlev closed 9 years ago

lajlev commented 9 years ago

Can't figure out how to make it work with multiple images, by using class name. Tried following without luck.

Caman('.caman-sketch', function () {
  this.brightness(10);
  this.contrast(30);
  this.sepia(60);
  this.saturation(-30);
  this.render();
});

But only worked on the first image with that classname.

meltingice commented 9 years ago

This is actually unsupported right now, but I have plans to add it in the future.

lajlev commented 9 years ago

Is there anyway I can achive to use Caman on multiple files with the same caman settings?

lajlev commented 9 years ago

Thanks for the quick response BTW :+1:

meltingice commented 9 years ago

Yeah, you could initialize each image separately with its own Caman object and then store them in an array. This would be pretty simple to do with promises.

// This is all totally untested FYI
var caman_objs = [];
function initImage(image) {
  new RSVP.Promise(function (resolve, reject) {
    caman_objs.push(Caman(image, resolve));
  }
}

RSVP.Promise.all(
  $(".caman-sketch").map(function(i, e) { initImage(e); })
).then(function () {
    // ready to use caman_objs
  }
);
``