Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Lerg
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lerg/8791632 to your computer and use it in GitHub Desktop.
Save Lerg/8791632 to your computer and use it in GitHub Desktop.
#!/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