Skip to content

toBuffer optimization #306

Closed
Closed
@kangax

Description

@kangax

I ran into performance issues with toBuffer. Here's an example of drawing (rather) large image onto canvas, then calling toBuffer. toBuffer is what's taking the longest here (drawImage, for example, is insignificant). I'm getting ~7-7.5 sec on toBuffer call. This is on node v0.10.13, node-canvas v1.0.3, and Mac OS X (10.7.5).

Is there a way to speed things up? Anything at all? I also tried async toBuffer but it doesn't really help.

var fs = require('fs'),
    Canvas = require('canvas'),
    Image = Canvas.Image;

// 3.9MB, 4686x4668
fs.readFile(__dirname + '/big_img.jpg', function(err, bigImg) {
  if (err) throw err;

  img = new Image;
  img.src = bigImg;

  var canvas = new Canvas(img.width, img.height);
  var ctx = canvas.getContext('2d');

  ctx.drawImage(img, 0, 0);

  console.time('toBuffer');
  canvas.toBuffer();
  console.timeEnd('toBuffer'); // 7196ms, 7435ms, 7237ms
});

Attaching image used in a test.

big_img

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions