Skip to content

Instantly share code, notes, and snippets.

@zinkkrysty
Created March 20, 2017 12:49
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 zinkkrysty/cb2bbda53d8da03d7c4f967c3fa81442 to your computer and use it in GitHub Desktop.
Save zinkkrysty/cb2bbda53d8da03d7c4f967c3fa81442 to your computer and use it in GitHub Desktop.
Resize and optimize images
#!/bin/bash
for image in $( ls *.{jpg,jpeg} ); do
# Get the width and height
height=`sips --getProperty pixelHeight $image | sed -E "s/.*pixelHeight: ([0-9]+)/\1/g" | tail -1`
width=`sips --getProperty pixelWidth $image | sed -E "s/.*pixelWidth: ([0-9]+)/\1/g" | tail -1`
if [[ $height -gt 600 || $width -gt 800 ]]; then
echo "large file ($image) needs reducing"
# This does the actual resizing
sips -Z 800x600 $image
fi
done
# To optimize run
# jpegoptim *.{jpg,jpeg}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment