Bash: rasterize function.

This commit is contained in:
Artem Sapegin 2012-12-12 17:59:18 +04:00
parent 50ea796c8a
commit 5b8ee712c4
2 changed files with 38 additions and 0 deletions

View File

@ -104,6 +104,10 @@ Upload current directory to special directory on my hosting.
Backup remote MySQL database to `~/Backups/hostname/dbname_YYYY-MM-DD.sql.gz`.
### rasterize <URL> <filename>
Save page screenshot to file.
## NPM

View File

@ -224,3 +224,37 @@ mysql-dump() {
echo "Done: $local_filepath"
fi
}
# Save page screenshot to file
# USAGE: rasterize <URL> <filename>
# Based on https://github.com/oxyc/dotfiles/blob/master/.bash/commands
function rasterize() {
local url="$1"
local filename="$2"
if [[ $url == "" ]] || [[ $filename == "" ]]; then
echo "Usage: rasterize <URL> <filename>"
else
header "Rasterizing $url..."
[[ $url != http* ]] && url="http://$url"
[[ $filename != *png ]] && filename="$filename.png"
phantomjs <(echo "
var page = new WebPage();
page.viewportSize = { width: 1280, height_: 1024 };
page.open('$url', function (status) {
if (status !== 'success') {
console.log('Unable to load the address.');
phantom.exit();
}
else {
window.setTimeout(function() {
page.render('$filename');
phantom.exit();
}, 1000);
}
});
")
echo "Screenshot saved to: $filename"
fi
}