Created
September 18, 2011 23:58
-
-
Save aperiodic/1225735 to your computer and use it in GitHub Desktop.
Node-canvas greyscale jpg bug example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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