Skip to content

Instantly share code, notes, and snippets.

@claudioc
Created May 29, 2020 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudioc/ac4be1843dded18cf86243dd8b668536 to your computer and use it in GitHub Desktop.
Save claudioc/ac4be1843dded18cf86243dd8b668536 to your computer and use it in GitHub Desktop.
Script which finds the newest screenshot image and adds a shadow to it
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo "Needs the filename as the first argument"
exit -1
fi
type /usr/local/bin/convert >/dev/null 2>&1 || { echo >&2 "The convert command must be available."; exit 1; }
input_filename="${1}"
output_dir="./"
if [ "${input_filename}" == "--last-screenshot" ]; then
ss_dir="/Users/claudioc/Screenshots/"
input_filename="$(ls -1rt ${ss_dir}Screenshot* | tail -1)"
if [[ "${input_filename}" =~ "_shadow" ]]; then
echo "Nothing to be done"
exit 0
fi
output_dir="${ss_dir}"
fi
# https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash#965072
filename=$(basename -- "${input_filename}")
extension="${filename##*.}"
filename="${filename%.*}"
/usr/local/bin/convert "${input_filename}" \( +clone -background black -shadow 30x8+0+0 \) +swap -background none -layers merge +repage "${output_dir}${filename}_shadow.${extension}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment