meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.56k stars 406 forks source link

Bad performances #150

Closed DanieleSassoli closed 4 years ago

DanieleSassoli commented 10 years ago

Hy, I don't need extremly fast performances but I would like to be sure that any image editing on any photo will take less than 45 seconds to be completed. I have done some tests and for a jpeg image of 5.22 MB with this effects: {"saturation":"5","sepia":"10","vibrance":"10","sharpen":"6","brightness":"5","contrast":"3","exposure":"5"} and preset = greyscale, my program takes up to 1 minute and 23 seconds to complete, I think that this is definitly to bad and I hope I'm getting something wrong or that there is a way I can achieve better perfomances, this is my code

var myimage = new Canvas.Image();
    myimage.onload = function() {
        Caman('C://images//' + req.body['storedName'], function () {
            var regulations = JSON.parse(req.body['regulations']);
            this.saturation(regulations.saturation);
            this.sepia(regulations.sepia);
            this.vibrance(regulations.vibrance);
            this.sharpen(regulations.sharpen);
            this.brightness(regulations.brightness);
            this.contrast(regulations.contrast);
            this.exposure(regulations.exposure);
            this[req.body['preset']]();
            this.render(function () {
                var extension = path.extname(req.body['storedName']);
                var filename = path.basename(req.body['storedName'],extension);
                this.save('C://images//' + filename + '-caman' + extension);
                res.json({ status:'success' });
            });
        });
    };
    myimage.onerror = function(err){
        console.log(err);
        res.json({status:"error", message:err});
    };
    myimage.src = 'C://images//' + req.body['storedName'];

I'm using a dual-core machine with 4 GB of ram with ubuntu 14.04.

meltingice commented 10 years ago

What browser are you using?

DanieleSassoli commented 10 years ago

chrome, but this script is running server-side, with nodejs. Sorry I should have mentioned that.

meltingice commented 10 years ago

That certainly seems high, but Caman tends to struggle with speed on high resolution images. A 5.22MB jpeg sounds like a very large image.

DanieleSassoli commented 10 years ago

Ok, but the images wich I'm going to deal with will be all in high resolution. I've read in #82 that setting allowRevert could increase performances, I tried but the time didn't change at all. Are there any other thing's I can try?

DanieleSassoli commented 10 years ago

Hy, I should probably open a new issue for this one, it's that I can't understand the image file size after CamanJS manipulation. My jpeg image with all the filter I described in the opening post generated another jpeg image(obviously) of 1.4 MB, and this is the good part, because with the greyscale preset the image becamed nealy black and white, but if I get rid of all the filters and everything my 5.22 MB jpeg becomes a 22 MB jpeg, is there a reason?

meltingice commented 10 years ago

In NodeJS it will only save the image as a PNG. Adding JPG export support should be a new issue.