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 to revert changes? #70

Closed klauskdk closed 11 years ago

klauskdk commented 11 years ago

In a node.js context - I want to process the same image multiple times with different filters, and save the image. From my understanding and some experiments with your module, I should revert the changes on the object, after every time I've processed the image and saved it, in order to avoid having to read the source file from disk multiple times.

The issue is - how do one revert changes? calling .revert(function(){...}) on my image object doesn't seem to work. The callback function is never called.

Any chance you could update the documentation with an example of reverting changes?

Thank you very much for this fine piece of work - and for your help!

meltingice commented 11 years ago

Revert no longer uses a callback because it is now synchronous.

  # Reverts the canvas back to it's original state while
  # maintaining any cropped or resized dimensions.
  revert: ->
    throw "Revert disabled" unless Caman.allowRevert

    @pixelData[i] = pixel for pixel, i in @originalVisiblePixels()
    @context.putImageData @imageData, 0, 0

Simply call the revert function and the image will be reverted back to it's original state. I'll go through the documentation and make sure it is updated to reflect this, sorry about the confusion!

klauskdk commented 11 years ago

Thank you very much for your reply - and sorting this out! I really appreciate the work you've guys put into this!