bash-toys/toys/meme-composer.sh

58 lines
958 B
Bash
Executable File

#! /bin/bash
#
# Create your own memes.
#
USAGE="USAGE: $0 img.jpg 'top text' 'bottom text'";
if ! [ -x "$(command -v convert)" ]; then
echo "convert(1) is not installed. Install it and try again."
exit 1;
fi
if [ -x "$(command -v fc-list)" ]; then
if [ -z "$(fc-list | grep 'Impact')" ]; then
echo "Impact font not installed..."
fi
else
echo "Cannot check id Impact font is installed. Try installing fontconfig.";
fi
IMG_INPUT=$1;
IMG_OUTPUT="meme-$IMG_INPUT";
TEXT_TOP="";
TEXT_BOTTOM="";
if [ -z "$IMG_INPUT" ]; then
echo "$USAGE";
exit 1;
fi
if ! [ -z "$2" ]; then
TEXT_TOP=$2;
fi
if ! [ -z "$3" ]; then
TEXT_BOTTOM=$3;
fi
convert "$IMG_INPUT" \
-font impact \
-fill white \
-pointsize 84 \
-stroke black \
-strokewidth 3 \
-gravity north \
-annotate +0+20 \
"$TEXT_TOP" \
-gravity south \
-annotate +0+20 \
"$TEXT_BOTTOM" \
"$IMG_OUTPUT"
if [ -f "$IMG_OUTPUT" ]; then
echo "";
echo "Created $IMG_OUTPUT";
echo "";
fi