Skip to content

Instantly share code, notes, and snippets.

@yrps
Created November 23, 2015 07:08
Show Gist options
  • Select an option

  • Save yrps/15f6687cfb20aef8d27f to your computer and use it in GitHub Desktop.

Select an option

Save yrps/15f6687cfb20aef8d27f to your computer and use it in GitHub Desktop.
ImageMagick to make my avatar
#!/bin/bash
# ImageMagick script to generate github/bitbucket avatar
# http://www.imagemagick.org/Usage/draw/
out=${HOME}/Documents/eagle.png
side=420
tile=60
marg=30
canvas="#f0f0f0"
fill="#008088"
secret="#cccccc"
stroke="#183c5c" # unused
map="\
011000
021011
111110
011100
001000
011100
"
# handle newline as a variable
n='
'
# initialize the command string and open the draw
cmd="convert -verbose -size ${side}x${side} xc:$canvas "
#cmd+="-stroke '${stroke}' "
x=$[marg]; y=$[marg]
for (( i=0; i<${#map}; i++ )); do
case ${map:${i}:1} in
0)
# unfilled tile increments x but draws no rectangle
#echo -n \#
x=$[x+tile]
;;
1)
# filled tile appends a rectangle in the main color
#echo -n .
cmd+="-fill '${fill}' -draw \"rectangle $x,$y $[x+tile],$[y+tile]\" "
x=$[x+tile]
;;
2) # secret filled tile appends a rectangle in the secondary color
#echo -n ,
cmd+="-fill '${secret}' -draw \"rectangle $x,$y $[x+tile],$[y+tile]\" "
x=$[x+tile]
;;
$n)
# newline resets x and increments y
#echo ~
x=$[marg]
y=$[y+tile]
;;
*)
# unrecognized char
#echo -n ?
esac
done
# close the draw and append output dest
cmd+=${out}
# execute the command
#echo $cmd
eval ${cmd}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment