Resize Multiple Images
October 20th, 2008
2 comments
Resize Multiple Images
In my case i need to change the size of more than 1,000 pictures so using gimp and scale everyone is not a good solution.
You need ImageMagick and Bash.
Subfolders:

script.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/bin/bash # fotos IFS=$'\t\n'; # Algunas fotos puede que tengan espacios for i in `ls`; do for j in `ls $i `; do # fotos/098-001/ fotos/098-002/ fotos/097-001/ etc... if [ "$j" = "Thumbs.db" ]; then # garbage file on win32 echo "Nothing to do..." elif [ "$j" = "script.sh" ]; then # this script file :D echo "Nothing to do..." else echo "Working ..." # do the job #convert "$i/$j" -resize 500 "$i/new_$j" #mv "$i/new_$j" "$i/$j" mogrify -resize 500 "$i/$j" fi done done |
Now all images are width: 500.
Now supose you have a lot of sub directories, you can use this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/bin/bash IFS=$'\t\n' EXTS=( jpg gif png JPG GIF PNG ) for EXT in ${EXTS[@]}; do for f in `find . -name "*.$EXT" -type f`; do dir=`dirname $f` ff=`basename $f` echo "Working ..." #convert "$f" -resize 500 "$dir/new_$ff" #mv "$dir/new_$ff" "$f" mogrify -resize 500 "$f" done done |
[thanks for the advice CyX]