This site is moved to other domain!

You should be automatically redirected in 9 seconds. If not, visit
http://www.detector-pro.com
and update your bookmarks.

Wednesday, January 14, 2009



Stumble Upon Toolbar
written by: Ukion in
[] [] [] [] [] []

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


Don't want to miss a single bit? Subscribe to our RSS Feed!


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=400x300
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.




Subscribe to DetectorProDid you enjoy this post? Why not leave a comment below and continue the conversation, or Subscribe to Feed and get articles like this delivered automatically to your Email or feed reader.



Related articles by tags



2 comments:

Anonymous said...

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

Anonymous said...

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