Skip to content

Instantly share code, notes, and snippets.

@aperiodic
Created September 18, 2011 23:58
Show Gist options
  • Save aperiodic/1225735 to your computer and use it in GitHub Desktop.
Save aperiodic/1225735 to your computer and use it in GitHub Desktop.
Node-canvas greyscale jpg bug example
/**
* Script to demonstrate node-canvas greyscale JPG bug
*
* example input: http://i.imgur.com/BrPWa.jpg
* example output: http://i.imgur.com/eg2Nc.png
*/
var Canvas = require('canvas')
, Image = Canvas.Image;
var fs = require('fs');
var squid = fs.readFileSync(__dirname + '/yalta.jpg');
img = new Image;
img.src = squid;
var canvas = new Canvas(img.width, img.height)
var ctx = canvas.getContext('2d')
ctx.drawImage(img, 0, 0, img.width, img.height);
var out = fs.createWriteStream(__dirname + '/yalta-out.png')
, stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment