1 2 3 4 5
#!/bin/sh size=512x512 convert "$1" -background white -flatten -alpha off -fx '(r+g+b)/3' -colorspace Gray -resize "$size" -gravity center -extent "$size" "$2"