Skip to content

Instantly share code, notes, and snippets.

@chrismdp
Last active June 7, 2017 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismdp/bee4c4e6f63f5d9c100fde063e34fbcf to your computer and use it in GitHub Desktop.
Save chrismdp/bee4c4e6f63f5d9c100fde063e34fbcf to your computer and use it in GitHub Desktop.
ImagicMagick + Shell script to generate my Kickstarter reward chart on this campaign: https://www.kickstarter.com/projects/chrismdp/ealdorlight?ref=2q0zxb
#!/bin/bash
TITLE_BG=title-bg.png
EL_BG=el-circle.png
OUT=achievements.png
# A colon-seperated rewards list.
# First column is the type of reward:
# <text> - a text number.
# Columns are alpha divisor (eg 4 is 25%), percentage complete, big number, smaller label and text description.
# <texticon> - a text icon only.
# Columns are alpha divisor (eg 4 is 25%), percentage complete, text for icon, font to use and text description.
# <icon> - an icon with number underneath
# Columns are alpha divisor (eg 4 is 25%), percentage complete, relative path to icon, smaller label and text description.
declare -a labels=(
"text:4:28:594:backers:Exceed the number\nof backers for\nSol Trader"
"text:4:10:100%:funded:Get\nEaldorlight to\nfully funded!"
"texticon:4:0:W:Garamond-Bold:Create an\nEaldorlight\nWikipedia page"
"icon:4:4:icons/twitter.png:100:100 retweets of\npinned @ealdorlight\ntweet"
"icon:4:61:icons/instagram.png:500:500 Instagram\n@revelation_games\nfollowers"
"icon:4:3:icons/facebook.png:100:100 shares\nof pinned video\non Ealdorlight page"
"icon:4:5:icons/reddit.png:100:100 reddit\nsubcribers to\n/r/ealdorlight"
"icon:4:0:icons/cake.png:5:5 Ealdorlight\nthemed\ncakes"
"icon:4:0:icons/paint-brush.png:5:5 pieces\nof Ealdorlight\nfan art"
"icon:4:0:icons/t-shirt.png:5:5 photos\nof Ealdorlight\ncosplay"
"icon:4:0:icons/scroll.png:10:10 verses of\nthe Ealdorlight\nballad"
"icon:4:0:icons/binoculars.png:10:10 photos of\nEaldorlight\nleads"
"texticon:10:0:?:Alegreya-Regular:More to come!"
"texticon:10:0:?:Alegreya-Regular:More to come!"
"texticon:10:0:?:Alegreya-Regular:More to come!"
)
#set -x
layers=(-size 1360x1500 xc:white)
layers+=(\( "$TITLE_BG" -resize 1800x2800 -repage -220+0 \))
layers+=(\( +clone -resize 1800x2800 -repage -220+1130 \))
layers+=(\( "$TITLE_BG" -resize 1800x2800\! -crop 1800x1280+0+1000 -repage +-220+120 \))
ix=-500
iy=-320
i=0
rowcount=5
wx=250
wy=380
for row in "${labels[@]}"; do
di=$(( $i / $rowcount ))
mi=$(( $i % $rowcount ))
x=$(( $ix + $mi * $wx ))
y=$(( $iy + $di * $wy ))
iconx=$((48 + ($mi * $wx) ))
icony=$((105 + ($di * $wy) ))
IFS=: read -r -a fields <<< "$row"
percentageheight=$(( 228 - (${fields[2]} * 200 / 100) ))
echo $percentageheight
# label
layers+=(\( -strokewidth 0 -stroke none -background none -pointsize 27 -fill white -font Alegreya-Regular -gravity center caption:"${fields[5]}" -repage +$x+$y \))
# icon
layers+=(\( "$EL_BG" -alpha set -channel A -evaluate Divide ${fields[1]} -repage +$iconx+$icony -fill transparent -strokewidth 7.5 -stroke white -draw "circle 133,128 202,193" -alpha set -channel A -evaluate Divide $(( ${fields[1]} / 2)) \))
layers+=(\( +clone -alpha set -channel A -evaluate Multiply 2 -strokewidth 10 -stroke "#004d39" -draw "circle 133,128 202,193" -crop 100%x100%+$iconx+$(( $icony + $percentageheight )) \))
case "${fields[0]}" in
text)
layers+=(\( -stroke none -background none -pointsize 60 -fill white -alpha set -channel A -evaluate Divide 1.5 -font Alegreya-Regular caption:"${fields[3]}" -repage +$x+$(($y - 230)) \))
layers+=(\( -stroke none -background none -pointsize 40 -fill white -alpha set -channel A -evaluate Divide 1.5 -font Alegreya-Regular caption:"${fields[4]}" -repage +$x+$(($y - 165)) \))
;;
texticon)
layers+=(\( -stroke none -background none -pointsize 125 -fill white -alpha set -channel A -evaluate Divide $(( ${fields[1]} / 2)) -font "${fields[4]}" -gravity center caption:"${fields[3]}" -repage +$x+$(($y - 200)) \))
;;
icon)
layers+=(\( -stroke none "${fields[3]}" -resize 90x -alpha set -channel A -evaluate Divide 2 -repage +$(($ix + 635 + $mi * $wx))+$((160 + $di * $wy)) \))
layers+=(\( -stroke none -background none -pointsize 60 -fill white -alpha set -channel A -evaluate Divide 1.5 -font Alegreya-Regular caption:"${fields[4]}" -repage +$x+$(($y - 150)) \))
;;
*)
echo "Unknown format"
esac
((i++))
done
convert "${layers[@]}" -flatten -background white "${OUT}"
@chrismdp
Copy link
Author

chrismdp commented Jun 7, 2017

Gives this image:

achievements

You'll need to brew install imagemagick first if you're on a mac, or read this for other platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment