Linux tip: Rename and resize images with bash script from console

By Detector | 14 January 2009



Do you have a big collection of images? Do you want to prepare them for publishing on the web, sending on email or any other purpose? In Linux robust graphic applications are not needed for renaming and resizing a lot of images. Linux have simple solution, a simple bash script can the job.

Here is the bash script:

#!/bin/sh
counter=1
root=mypict
resolution=400×300
for i in `ls -1 $1/*.jpg`; do
echo “Now working on $i”
convert -resize $resolution $i ${root}_${counter}.jpg
counter=`expr $counter + 1`

Save the script in a file called picturework.sh and make it executable with

chmod u+x picturework.sh

and store it somewhere in your path. Now, if you have a bunch of .jpg files in the directory /path/to/dirpic, all you have to do is to execute

picturework.sh /path/to/dirpic

and in the current directory you’ll find mypict_1.jpg, mypict_2.jpg etc, which are the resized versions of your original ones. You can change the script according to your needs.

Tags | , , , , ,

| |

2 Responses to “Linux tip: Rename and resize images with bash script from console”

  1. upbeat.linux says:

    Keep in mind to run convert the imagemagick package needs to be compiled.

  2. Anonymous says:

    might need a “done” at the end of the script. (bash)






Archives

Add to Technorati Favorites
website stats
TwitterCounter for @ukion