Skip to content

Instantly share code, notes, and snippets.

@themarcthomas
Last active August 29, 2015 14:00
Show Gist options
  • Save themarcthomas/11404108 to your computer and use it in GitHub Desktop.
Save themarcthomas/11404108 to your computer and use it in GitHub Desktop.
ImageMagick Shell Command for Discount Codes
#!/bin/sh
#
# Uses ImageMagick to add text to an image based on Graham Ashton's Gist: https://github.com/gma/moo-card-codes.
COLOR="${COLOR:-black}"
FONT="${FONT:-Courier-Bold}"
FONT_SIZE="${FONT_SIZE:-31}"
TEMPLATE="${TEMPLATE:-template.jpg}"
TEXT_POSITION_X="${TEXT_POSITION_x:-+450}"
TEXT_POSITION_Y="${TEXT_POSITION_Y:-+365}"
## Main program
[ -n "$DEBUG" ] && set -x
let i=1
read CODE
while [ -n "$CODE" ]; do
OUTPUT="card-$(printf '%03d' $i).jpg"
echo "Creating $OUTPUT with code $CODE"
convert $TEMPLATE -pointsize $FONT_SIZE -fill $COLOR -font $FONT -annotate $TEXT_POSITION_X$TEXT_POSITION_Y $CODE $OUTPUT
let i=i+1
read CODE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment