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

How do I set a property of a caman object already created? #76

Closed bostondevin closed 11 years ago

bostondevin commented 11 years ago

Is there a way to update the properties of a caman object that's already been created? I'd like to attach a slider ui to contrast and brightness and cause the image to change accordingly- not sure how to update the brightness without recreating a whole new object... maybe i'm missing something.

meltingice commented 11 years ago

There are two ways you can access the Caman object. You can either store the result from the Caman function or call the Caman function on the same element.

// Calling Caman() on an uninitialized image or canvas will initialize it.
// It will also return a reference to the initialized Caman object.
var image = Caman("#my-image");

image.revert(); // Revert any changes to the image
image.brightness(10).render(); // Adjust the brightness and re-render (this is async!)

// If you call Caman() on the same element
var image2 = Caman("#my-image"); // image == image2

// This will not re-initialize Caman, but will load the already
// existing reference.
Caman("#my-image", function () {
  this.revert();
  this.brightness(10);
  this.render();
});

I hope that clears things up! Let me know if you're still confused.