Skip to content

Instantly share code, notes, and snippets.

@deltheil
Last active December 17, 2015 19:39
Show Gist options
  • Save deltheil/5661675 to your computer and use it in GitHub Desktop.
Save deltheil/5661675 to your computer and use it in GitHub Desktop.
Split in two parts, chop and join a transparent button image with ImageMagick.
#!/bin/sh
function split { # file, target_size
_w=$(identify -format "%w" $1)
_dx=$(( ($_w - $2) / 2 ))
convert $1 -crop 50%x100% +repage parts.png
convert parts-0.png -gravity East -chop ${_dx}x0 left.png
convert parts-1.png -gravity West -chop ${_dx}x0 right.png
montage -background none left.png right.png -mode Concatenate -tile x1 out.png
rm parts*.png left.png right.png
}
split $1 $2
echo "Done: out.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment