Coding, Server Management

Recursively resizing all the images in a folder and inside sub-folders using the Terminal

Recently, I had to resize about 1000’s of JPG pictures that were given to me which were HUGE in size about 10MB each pic to be converted/resized for the web.

I realized that I had to use my Terminal Hackery to solve this issue. I quickly installed “imagemagick”, which can be installed in OSX by :

brew install imagemagick

Or in Linux ( Debian – Ubuntu ) with :

sudo apt-get install imagemagick

After which I went to the folder which had the images inside the subfolder and I ran this command :

find . -name '*.jpg' -type f -exec bash -c 'convert -resize 60% -quality 80 "$0" "${0%.jpg}-small.jpg" && echo "Converted : $0"' {} \;

And voila! All the images were converted into smaller versions of the images. The new files had the “small” in their title. This helped me figure out which photos to upload while also preserving the originals.

Leave a Reply

Your email address will not be published. Required fields are marked *