Created
March 20, 2017 12:49
-
-
Save zinkkrysty/cb2bbda53d8da03d7c4f967c3fa81442 to your computer and use it in GitHub Desktop.
Resize and optimize images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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