Skip to content

Instantly share code, notes, and snippets.

@Jeswang
Last active August 29, 2015 14:11
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 Jeswang/04ea64f4708e476c5670 to your computer and use it in GitHub Desktop.
Save Jeswang/04ea64f4708e476c5670 to your computer and use it in GitHub Desktop.
Transform images
function halfPNGs(){
dir=$1
n=0
while read f
do
# Image name
i=$(basename "$f")
echo $i
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 '*@2x.png') # Find all pngs in directory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment