Skip to content

Instantly share code, notes, and snippets.

@puppybits
Created January 2, 2012 13:47
Show Gist options
  • Save puppybits/1550741 to your computer and use it in GitHub Desktop.
Save puppybits/1550741 to your computer and use it in GitHub Desktop.
resize @2x pngs to @1x iphone images for an entire folder
function halfPNGs(){
dir=$1
n=0
while read f
do
# Image name
i=$(basename "$f")
if [[ $i == *\@2x\.png ]]; then
# Height of image
h=$(sips -g pixelHeight $f)
# Cut off all but the numbers
h=${h#*:}
# Width of image
w=$(sips -g pixelWidth $f)
# Cut off all but the numbers
w=${w#*:}
# Resize the png and output in the same folder with @2x cut off
sips -s format png -z $(expr $h / 2) $(expr $w / 2) $f --out ${f%@*}\.png
fi
done < <(find $dir -iname *.png) # Find all pngs in directory
}
# Example usage
# halfPNGs ~/Desktop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment