Skip to content

Instantly share code, notes, and snippets.

@tzermias
Created February 10, 2021 17:24
Show Gist options
  • Save tzermias/d23df85cf2268c8c1d50fcd3ac2eba32 to your computer and use it in GitHub Desktop.
Save tzermias/d23df85cf2268c8c1d50fcd3ac2eba32 to your computer and use it in GitHub Desktop.
Meme Generator using ImageMagick
#!/bin/bash
# meme.sh
# Meme generator with ImageMagick
# https://www.it-cooking.com/technology/digital-image/image-processing/meme-generator-imagemagick/
usage() {
echo "Usage: $0 [ -t TOP_MSG ] [ -b BOTTOM_MSG ] SRC DST"
}
failure() {
usage
exit 1
}
bottom_msg="BOTTOM MSG"
top_msg="TOP MSG"
while getopts "hb:t:" opt; do
case ${opt} in
b )
bottom_msg=$OPTARG
;;
t )
top_msg=$OPTARG
;;
h )
usage
exit 0
;;
: )
exit_abnormal
;;
* )
exit_abnormal
;;
esac
done
shift $((OPTIND -1))
SIZE=$(identify -format "%[fx:w]x%[fx:h]" $1)
convert $1 \
-gravity North \
\( -size $SIZE xc:none -font Impact -pointsize 50 -stroke black -strokewidth 7 -annotate 0 "${top_msg}" -blur 0x1 \) -composite \
-size $SIZE -font Impact -fill white -pointsize 50 -stroke none -annotate 0 "${top_msg}" \
-gravity South \
\( -size $SIZE xc:none -font Impact -pointsize 50 -stroke black -strokewidth 7 -annotate 0 "${bottom_msg}" -blur 0x1 \)\
-size $SIZE -font Impact -fill white -pointsize 50 -stroke none -annotate 0 "${bottom_msg}" -composite\
$2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment