Rojakcoder
Of Linux, Programming, and Singaporean Ramblings

Resizing Multiple Images in Linux

Sun, Nov 29, 2009 11:25PM +0800

During the lifetime of using the computer, I believe everyone will inevitably face the scenario where you will want resize multiple images to a certain size.

In Linux, you can do it will such ease that makes you wonder what you use Windows for.

This effect can be easily done using the command line. Naysayers will probably disclaim the effectiveness of this tip but it really is easy for those who know Linux. All you have to do is to go into the directory where the images are stored and run the following command:

for k in $(ls *.jpg); do convert $k -resize 1024x768 -quality 100 re_$k; done

You can make it even easier for you by placing the above line into a file i.e. type the above code and save it in a file. Name the file “resize.sh” and save it in your home directory’s bin sub-directory.

E.g. /home/coder/bin/resize.sh (replace ‘coder’ with the your own user name)

From the command line, add the executable rights to the file using the command:

c h m o d +x /home/coder/bin/resize.sh (The letters ‘c’, ‘h’, ‘m’, ‘o’, ‘d’ should be combined into a single word ‘chmod’ – the reason why they are separated is that WordPress doesn’t allow posting of the word, for what reason, I don’t know. See my other post “Weird Problem with WordPress“.)

Then you can just go to the directory where the images are and apply the changes.

P.S. always make a backup of the images before you see this.

Update - 2014 Jun 18

The problem with regards to chmod mentioned above is no longer applicable because this site is now using a static site generator.

Tags: linux bash
comments powered by Disqus