Last active
August 29, 2015 13:56
-
-
Save madeingnecca/9060277 to your computer and use it in GitHub Desktop.
BASH - create screenshots for cms themes
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
#!/bin/bash | |
pageres_res="1024x768" | |
website=$1 | |
shift | |
while test $# -gt 0 | |
do | |
case "$1" in | |
--drupal) | |
w=294 | |
h=219 | |
screenshot_filename="screenshot.png" | |
shift | |
;; | |
--wordpress) | |
w=880 | |
h=660 | |
screenshot_filename="screenshot.png" | |
shift | |
;; | |
*) | |
shift | |
;; | |
esac | |
done | |
if [[ "$w" = "" || "$h" = "" ]] | |
then | |
echo "Please provide a preset (drupal/wordpress). E.g: $0 --drupal" | |
exit 1 | |
fi | |
pageres_output="$website-$pageres_res.png" | |
# Pageres removes protocol information from the url. So let's do the same. | |
pageres_output=${pageres_output/http:\/\//} | |
pageres_output=${pageres_output/https:\/\//} | |
# Pageres removes "www." from hostnames. So let's do the same. | |
pageres_output=${pageres_output/www./} | |
# Pageres converts slashes to "!". So let's do the same. | |
pageres_output=${pageres_output//\//!} | |
pageres "$website" --sizes "$pageres_res" | |
if [ $? -eq 1 ] | |
then | |
echo "Failed to take a screenshot of $website." | |
exit 1 | |
fi | |
convert "$pageres_output" -resize "${w}x" -gravity North -crop "${w}x${h}"+0+0 "$screenshot_filename" | |
if [ $? -eq 1 ] | |
then | |
echo "Failed to resize the screenshot." | |
exit 1 | |
fi | |
# Remove pageres output. | |
rm "$pageres_output" | |
echo "Screenshot done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment