Tags for Bash script to resize images recursively and place them i a new directory

Bash script to resize images recursively and place them i a new directory

Running out off disk space on you mobile device like Tabled, Phone of laptop and because of the big file size of your photo files? But you do not want to delete your photos? Resize them to small files.

First: copy all your original photos to a backup medium like a Desktop PC, Server or a NAS. Rename the photo directory to Pictures. So that the pictures are in /home/rob/MyDocs/Pictures . You may have as many subdirectories as you want with directories names you made yourself.

The structure looks like this:

  • /home/rob/MyDocs/Pictures/album_1
  • /home/rob/MyDocs/Pictures/album_2
  • /home/rob/MyDocs/Pictures/holliday/2012
  • /home/rob/MyDocs/Pictures/holliday/2013
  • /home/rob/MyDocs/Pictures/mydog/2010
  • /home/rob/MyDocs/Pictures/mydog/2012
  • and so on.....

Place the scrip in ./Pictures and run is with:


Note: not sh
Or give file execution permission whith and run it:

chmod 755

The script build the same directory structure besides the ./Picture/ dir with the name ./Picture_Small/ with the same subdirs. The photo files are resize to 1024 px.


# By Rob Groen 0ctober 2014
# Resize pictures (*.jpg|JPG) and put them in a new create directory (if not excist)
# Script needs to be executed in de dir above ./Picture if the
# picturers ar in /home/rob/MyDocs/Pictures place the script in
# like /myDocs an run bash   (**** Use bash NOT sh *****)

for IN in `find ./Pictures -iname "*.jpg" -o -iname "*.png"`
DIR=$(dirname $OUT)
mkdir -p "$DIR"
if [ ! -f $OUT ]; then
echo "$COUNT Converting $IN"
convert $IN -resize 1024  $OUT
echo "$COUNT Skip $IN converted al ready."


This script resize images recursively

Post new comment
The content of this field is kept private and will not be shown publicly.
Deze vraag is om te controleren of u een persoon bent. Di is om spam berichten tegen te gaan.