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

NodeJS save but no effect #27

Closed ubraz closed 12 years ago

ubraz commented 12 years ago

Hi, I'm testing the CamanJS and I have a little issue. Using the nodejs, the pictures are saved, but none effect was applied.

My nodejs code:

var sys   = require('util'),
    caman = require('/usr/lib/node_modules/caman/dist/caman.full.js');

sys.puts("started...");
var image = caman.Caman('/opt/node/001.jpg', function() {
    this.sunrise();
    this.render();
    this.save('/opt/node/001_save.png');
});

My script is wrong or something is not working.

Thanks in advance.

meltingice commented 12 years ago

Rendering is asynchronous, so you have to put save() in a callback like this:

var image = caman.Caman('/opt/node/001.jpg', function() {
    this.sunrise();
    this.render(function () {
        this.save('/opt/node/001_save.png');
    });
});