Archivo

Entradas Etiquetadas ‘image’

Resize Multiple Images

lunes, 20 de octubre de 2008 Albertux 2 comentarios

Resize Multiple Images

En mi caso tengo que cambir el tamaño de mas de 1,000 fotografias asi que si utilizo gimp y las escalo cada una no es una buena solución.

Necesitas ImageMagick y 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

Ahora todas las imagenes tienen width: 500.

Ahora supongamos que se tienen multiples sub directorios, puedes utilizar este 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]

Categories: unix/linux Tags: , ,