Skip to content

Instantly share code, notes, and snippets.

@lanceli
Created February 16, 2013 09:15
Show Gist options
  • Save lanceli/4966207 to your computer and use it in GitHub Desktop.
Save lanceli/4966207 to your computer and use it in GitHub Desktop.
sips downscale image by percentage in Mac OS X
#!/bin/bash
if [ $1 ]
then
echo Processing file $1;
else
for var in `find *.png`;
do
echo Processing file $var;
sips -Z $(($(sips -g pixelWidth "$var" | cut -s -d ':' -f 2 | cut -c 2-) / 2)) "$var" --out "resized_$var" &> /dev/null
done
fi
@yura415
Copy link

yura415 commented Oct 9, 2015

Good work!

Fixed mess with spaces in path:

#!/bin/bash

if [ $1 ]
then
   echo Processing file $1;
else
   find "*.png" -print0 | while IFS= read -r -d '' file; do
       echo Processing file "$file";
       sips -Z $(($(sips -g pixelWidth "$file" | cut -s -d ':' -f 2 | cut -c 2-) / 2)) "$file" --out "$file" &> /dev/null
   done
fi

Also here is recursive version:

#!/bin/bash

if [ $1 ]
then
   echo Processing file $1;
else
   find . -name "*.png" -print0 | while IFS= read -r -d '' file; do
       echo Processing file "$file";
       sips -Z $(($(sips -g pixelWidth "$file" | cut -s -d ':' -f 2 | cut -c 2-) / 2)) "$file" --out "$file" &> /dev/null
   done
fi

Warning! These two scripts will override your files! So make sure that you've made your backups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment