Skip to content

Instantly share code, notes, and snippets.

@frullah
Last active November 1, 2020 15:25
Show Gist options
  • Save frullah/5c28771c9e500901fdb9cb680ad3c75e to your computer and use it in GitHub Desktop.
Save frullah/5c28771c9e500901fdb9cb680ad3c75e to your computer and use it in GitHub Desktop.
#!/bin/bash
# requirements:
# - pageres-cli (https://github.com/sindresorhus/pageres-cli)
# CLI website screenshot tool
# - crunch (https://github.com/chrissimpkins/Crunch)
# PNG image optimizer
#
# usage:
# see https://github.com/sindresorhus/pageres-cli#usage
# don't use `--format` argument, let script do it automatically
# it will result as PNG, because Crunch only support PNG
#
# output: inside directory "pageres_{date}_{time}_{nanoseconds}"
if [ $# -eq 0 ]; then
pageres --help
exit 1
fi
set -e
# get date, time, and nanoseconds as timestamp
timestamp=$(date +%F_%T_%N)
(
# create directory with current timestamp and go inside
out_dir="pageres_${timestamp}"
mkdir $out_dir
cd $out_dir
echo "Taking screenshots..."
pageres $@ --format png
out_filenames=$(find * -maxdepth 0 -type f -name "*.png" -print0 | xargs -0)
echo "Compressing..."
crunch $out_filenames
echo "Finishing..."
for filename in $out_filenames; do
base_filename=$(basename -s .png $filename)
mv "${base_filename}-crunch.png" $filename --force
done
)
echo "Done!"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment