Last active
July 25, 2016 11:08
-
-
Save marsam/82c68c5a42e6f4c97927 to your computer and use it in GitHub Desktop.
tweetshot --- take screenshot to tweets
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/bin/env phantomjs | |
/*global phantom: false */ | |
'use strict'; | |
var system = require('system') | |
, args = system.args | |
, page = require('webpage').create() | |
; | |
var tweetshot = function(url, output, width, height) { | |
width = width || 1280; | |
height = height || 1024; | |
output = output || 'tweetshot.' + width + 'x' + height + '.png'; | |
page.viewportSize = { width: width, height: height }; | |
page.open(url, function(status) { | |
if (status !== 'success') { | |
console.log('Unable to load url: ' + url); | |
phantom.exit(); | |
} | |
window.setTimeout(function() { | |
page.clipRect = page.evaluate(function() { | |
var tweet = document.querySelector('[role="main"]'); | |
return tweet === null? {} : tweet.getBoundingClientRect(); | |
}); | |
console.log('Creating file: ' + output); | |
page.render(output); | |
phantom.exit(); | |
}, 200); | |
}); | |
}; | |
if (args.length === 1) { | |
console.log('Usage: ' + args[0] + ' URL [output] [width] [height]'); | |
phantom.exit(); | |
} | |
tweetshot(args[1], args[2], args[3], args[4]); | |
// Local Variables: | |
// mode: js | |
// End: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the clipRect, I added this to remove replies: