-
-
Save GregHilston/2d848165b936a79c20a2424b75890940 to your computer and use it in GitHub Desktop.
This Gist assists you in creating a screen shot of a Gist. I use it to post screen shots on LinkedIn.
This file contains 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
#!/usr/local/bin/phantomjs | |
var page = require('webpage').create(); | |
var system = require('system'); | |
// ***** Argument handling | |
function isInt(value) { | |
return !isNaN(value) && | |
parseInt(Number(value)) == value && | |
!isNaN(parseInt(value, 10)); | |
} | |
if ( system.args.length !== 4 ) { | |
console.log('Usage: gist-to-png.js <gist-ID> <lines> <filename>'); | |
console.log(' <gist-ID> - the ID of the Gist, from the URL, e.g. 2ab741a36788a38b459e'); | |
console.log(' <lines> - number of lines in the Gist'); | |
console.log(' <filename> - output file'); | |
phantom.exit(); | |
} | |
var id = system.args[1]; | |
var lines = system.args[2]; | |
var output = system.args[3]; | |
var url = 'https://gist.github.com/GregHilston/' + id; | |
if ( ! isInt(lines) ) { | |
console.log('The number of lines is not an integer: ' + lines); | |
phantom.exit(); | |
} | |
// ***** Processing | |
// the portion of the page to take a screenshot of | |
page.clipRect = { | |
top: 275, | |
left: 10, | |
width: 790, | |
height: ( 18 * parseInt(lines, 10) ) + 2 | |
}; | |
page.open(url, function(status) { | |
if (status !== 'success') { | |
console.log('FAIL to load the URL: ' + url); | |
} | |
else { | |
page.render(output); | |
phantom.exit(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment