-
-
Save joshuaflanagan/77f31411d137aec9b9c1b79b42d339f8 to your computer and use it in GitHub Desktop.
Meme Generator using ImageMagick
This file contains hidden or 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 | |
# meme.sh | |
# https://gist.github.com/joshuaflanagan/77f31411d137aec9b9c1b79b42d339f8 | |
# 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 ] [ -s FONTSIZE=80] [ -a TOP_FONTSIZE=80 ] [ -z BOTTOM_FONTSIZE=80 ] SRC DST" | |
} | |
failure() { | |
usage | |
exit 1 | |
} | |
bottom_msg="" | |
top_msg="" | |
tmsg_size=80 | |
bmsg_size=80 | |
while getopts "hb:t:s:a:z:" opt; do | |
case ${opt} in | |
b ) | |
bottom_msg=$OPTARG | |
;; | |
t ) | |
top_msg=$OPTARG | |
;; | |
s ) | |
tmsg_size=$OPTARG | |
bmsg_size=$OPTARG | |
;; | |
a ) | |
tmsg_size=$OPTARG | |
;; | |
z ) | |
bmsg_size=$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 ${tmsg_size} -stroke black -strokewidth 7 -annotate 0 "${top_msg}" -blur 0x1 \) -composite \ | |
-size $SIZE -font Impact -fill white -pointsize ${tmsg_size} -stroke none -annotate 0 "${top_msg}" \ | |
-gravity South \ | |
\( -size $SIZE xc:none -font Impact -pointsize ${bmsg_size} -stroke black -strokewidth 7 -annotate 0 "${bottom_msg}" -blur 0x1 \)\ | |
-size $SIZE -font Impact -fill white -pointsize ${bmsg_size} -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