Skip to content

Instantly share code, notes, and snippets.

@MrBri
Created April 1, 2013 21:36
Show Gist options
  • Save MrBri/5287954 to your computer and use it in GitHub Desktop.
Save MrBri/5287954 to your computer and use it in GitHub Desktop.
Take a screen shot of a website, resize it, and emit it back to the client.
// Error checking taken out for brevity
io.sockets.on('connection', function(client){
client.on('capture', function (url) {
var webshotOptions = {
screenSize: { width: 620, height: 620 },
shotSize: { width: 620, height: 620 }
},
pageObj = {},
imgPath = './img/' + url + '.png';
// PhantomJS
webshot(url, imgPath, webshotOptions, function(err) {
pageObj.url = url;
pageObj.imgOut = './img/' + url + '-resized.png';
// GraphicsMagick
gm(fs.createReadStream(imgPath), url + '.png')
.resize(155, 155)
.write(pageObj.imgOut, function (err) {
client.emit('resized', pageObj);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment