Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
rm _*.png
s=${1:-32}
ss=$((s+2))
for f in $(find . -name "*@2x.png" -maxdepth 1); do
echo "Paddding $f..."
wo=`convert $f -ping -format "%w" info:`
h=`convert $f -ping -format "%h" info:`
w=$((wo + (wo / s)*2))
convert $f \
-crop ${s}x0 +repage \
-define distort:viewport=${ss}x${h}-1-0 \
-filter point \
-distort SRT 0 +repage +append \
-crop 0x${s} +repage \
-define distort:viewport=${w}x${ss}-0-1 \
-distort SRT 0 +repage -append \
_$(basename $f)
done
for f in $(find . -name "_*@2x.png" -maxdepth 1); do
echo "Downsizing $f..."
# Remove "-filter Point" for smooth downscaling
convert "$f" -filter Point -resize '50%' "$(dirname $f)/$(basename -s "@2x.png" $f).png"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment