Search

bash convert resize and numerically rename multiple files

bash convert resize and numerically rename multiple files

As an addendum to my previous post today I needed to resize and rename a directory of images at the bash prompt.

A nice little one liner did it for me:
i=0; for f in *JPG; do a=my_new_filename_`printf "%04d" $i`.jpg; echo Converting $f to $a; convert -resize 25% $f resized/$a; let i=i+1; done

For the multiline purists:
i=1
for f in *JPG
do
a=my_new_filename_`printf "%04d" $i`.jpg
echo Converting $f to $a
convert -resize 25% $f resized/$a
let i=i+1
done

Related posts

Leave a Comment