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

.revert() fails if instantiated with canvas obj #52

Closed max-degterev closed 11 years ago

max-degterev commented 11 years ago

Everything works like a charm up to the point where I try to get original image back to the canvas. It looks like when you instantiate your Caman object like this:

    this.ctx.drawImage(opt.image, opt.cx, opt.cx, 640, 640, 0, 0, 640, 640);
    this.active && (delete this.caman);
    this.deactivate();
    this.caman = Caman(this.canvas, function() {
        that.activate();
    });

and then somewhere you do this:

        if (!that.active) return;

        type = this.getAttribute('data-filter');

        if (typeof that.filters[type] === 'function') {
            that.deactivate();
            that.caman.revert(applyFilter);
        }

you get this error:

TypeError: this.options is undefined return this.loadCanvas(this.options.image, this.canvas, ready);

If I switch to cropping via Caman, will it be OK? Or should I just repaint canvas myself?

max-degterev commented 11 years ago

I'd be really awesome if you could just say heres my image, please put canvas within this container, or here's canvas paint on it. And then you can crop it via caman or whatever.

meltingice commented 11 years ago

Caman supports cropping/resizing the canvas already:

Caman("#image", function () {
  this.crop(width, height, x, y);
  this.render();
});

Some improvement needs to be done in handling DOM objects that are given during initialization still.