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

Calling filters on returned instance fails #51

Closed max-degterev closed 11 years ago

max-degterev commented 11 years ago

Hi!

I'm building an instargam-like webapp that allows you to upload filtered images to a server.

I'm having an issue with returned instance of caman

Using it like this:

    this.caman = Caman(this.canvas, function() {
        this.sepia(40).saturation(5).render();
    });

works OK. However this:

    this.caman = Caman(this.canvas);
    this.caman.sepia(140).render();

fails with this error: http://imm.io/LXPy

TypeError: this.c.pixelData is undefined n = this.c.pixelData.length;

meltingice commented 11 years ago

This is because initialization is asynchronous as well, not just rendering. You're calling render() on the instance before the pixelData is read.

max-degterev commented 11 years ago

Can you look it up before closing it?

    this.caman = Caman(this.canvas);
    var that = this;
    $(window).on('load', function() {
        setTimeout(function(){
            that.caman.sepia(140).render();
        }, 3000);
    });

Same result.

meltingice commented 11 years ago

Apologizes, I just realized what the problem is. Currently Caman assumes it's been given an image when it's initialized with only 1 argument. This is something that should be fixed. I'll work on it today.

max-degterev commented 11 years ago

Great many thanks!

meltingice commented 11 years ago

That should do the trick. Remember, initialization is still asynchronous, but you can now initialize a canvas that already has image data in it with no problem.