Here goes!
Can this be done all together, can any part be easily done?
I'm on a Mac
Thanks in advance
I would do it with ImageMagick. The command is like this, but I would create a backup first:
#!/bin/bash
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -o -iname "*.png" | \
while read i; do
echo convert "$i" -resize 800x800 -quality 85% "$i"
done
That says... starting at dot
(the current directory, you can put a different starting directory here if you like), find all files called ".JPG" or ".JPEG" or ".GIF" or ".PNG", regardless of upper or lower case, in this directory and all directories below, and pass their names into the while loop. The convert
command says to resize the image so neither side is over 800px and the aspect ratio is retained, then optimise for Web and overwrite original file.
At the moment, it does nothing, it just shows you the command it would run, so you would need to remove the word echo
and run it again if you like it. Run some tests on a single image or two first.
You could add -strip
between -resize
and -quality
to remove EXIF data (date/time photo was taken, camera make and lens etc) to make the files smaller too. You can also insert a Copyright string and an IPTC profile to give Copyright, Contact, Source, Object and Credits information - just ask me.
To run the script above, save it in a file called resizer
, then go into Terminal and do this:
chmod +x resizer # Just do this one time to make the script executable
./resizer # Run the script
To install ImageMagick on a Mac, use homebrew
. Go to here and install it with the line of code there. Then do:
brew install imagemagick
If you don't like ImageMagick, you could maybe use sips
which is built into OSX but it is nowhere near as flexible. If you wanted to try that, the basic command would be:
sips -Z 800 somefile.jpg
and it will then resize the image to max 800px on either side. Not sure how to optimise or strip EXIF in sips
, nor if it works for PNG
and GIF
files... Your command would then become:
#!/bin/bash
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -o -iname "*.png" | \
while read i; do
echo sips -Z 800 "$i"
done