Wednesday, March 12, 2008

You can do it in Linux [1]

Who doesn't have a digital camera these days? If you don't, go and get one! It's so easy, fun, fast and cheap to take pictures of everything and everyone. You go on a trip and take lots of photos. Or get together with your friends and take lots of pictures, and of course you would like to share them with everybody else. So, you post them on flick, picasa, facebook, hi5 or your own website, even send them by email. Awesome!, isn't it? Well, sometimes is not that awesome. What do you do if you have 50 high resolution photos about 4 MB each and you want to uploaded them to the network? Are you going to send a 200 MB email? or wait an eternity to upload them in full quality when people will actually see them in a size 10 times smaller? It looks like a size reduction would be convenient. You launch your favorite image editor, open the photo, click the menus to get to the resizing option, select the new size, and save the photo with a new name. Are you going to repeat the process another 49 times? That's insane! but people have done it. Maybe you are lucky and you got some fancy software or website that do it for you... or maybe not. And what if you have your own web page and you want to display thumbnails of all your pictures, organize them in a table with four columns and link each thumbnail to a larger size version but not as large as the original one? Maybe you are still lucky and you got a package to do that... or maybe not... Thus you imagine yourself doing that boring task one by one during the next few hours, you bitterly face your reality and start the process... If only there was some clever thing to do... Well, there is. Too bad you have Windows in your computer. Had you been using Linux, things would have been different.

Many people know about Linux, but many more don't know about it. Linux is simply other operative system, far superior to Windows. Although people prefer Windows because it works, I changed to Linux long ago because it lets me work [2]. I'm not going to mention the pros and cons of each one because you can find them all over the Internet. What I'm going to say is that the problem of the pictures occurred to me and is easily solved with Linux. What is the solution? Just write a shell script.

In Linux you don't need graphical interfaces to do something. You can do a lot more working with the text-based terminal. The terminal is like the Windows DOS, where you type commands to do stuff. Linux has a huge collection of commands. There are even image manipulation commands, like those provided by ImageMagick. Resizing one image takes a single command. Resizing several images can be done in seconds with a single line script like this:

for i in *jpg; do convert $i -resize 320x240 th-$i; done

And that's it. We are done. We created a series of thumbnails of all the pictures in that directory. With more patience you can write a script that makes the thumbnails, writes the html code to organize them in a table and links them to a bigger size photo. It will take you some time to learn the basics of shell scripting and to make your own script, but it's worth the effort. Next time you have a bunch of photos you will simply run your script and create your gallery in the blink of an eye. If you don't like the thumbnails because they are too big... just change two numbers in your script and generate all of them again!

Additional side effects include: (1) Getting smarter because you put your brain to work. (2) Acquisition of a new skill that you can apply in other situations.

There is no down side in investing some time to learn something useful.

Needless to say, people do well in life without knowing about Linux, shell scripts and a bunch of other things. Nobody can use the knowledge that they don't possess.

[1] To be fair, you can also do it with a Mac.
[2] I'm well aware of the limitations of Linux. I rather deal with them than with the arbitrary nuisance and inefficiency of Windows.
Post a Comment