Skip to content

Instantly share code, notes, and snippets.

@acrookston
Created February 25, 2014 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acrookston/9218807 to your computer and use it in GitHub Desktop.
Save acrookston/9218807 to your computer and use it in GitHub Desktop.
Downsamples all retina @2x.png images
#!/bin/bash
# Downsamples all retina ...@2x.png images.
# Requires `sips` to be installed
echo "Downsampling retina images..."
dir=$(pwd)
find "$dir" -name "*@2x.png" | while read image; do
outfile=$(dirname "$image")/$(basename "$image" @2x.png).png
if [ "$image" -nt "$outfile" ]; then
basename "$outfile"
width=$(sips -g "pixelWidth" "$image" | awk 'FNR>1 {print $2}')
height=$(sips -g "pixelHeight" "$image" | awk 'FNR>1 {print $2}')
sips -z $(($height / 2)) $(($width / 2)) "$image" --out "$outfile"
test "$outfile" -nt "$image" || exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment