Pages

Thursday, June 21, 2012

Converting imagefiles

Using your digital camera or mobile phone makes it easy to take snapshots you want to share online, on facebook or by email. But the size of these images can be quite big since many cameras and mobile phones take pictures at 8-12 Megapixels. Then it is nice to know about the convert-command on linux that will allow you to batch convert images.

It even allows you to easily rename your images if you resize them to 100%.

So what do we need to use this little command?
In the package-manager of your favourite distro you will find the imagemagick package. This package includes the convert command.

On Ubuntu you could just run:

sudo apt-get install imagemagick

After you have installed this package the convert command should be ready for use.

I usually crete a new directory for the files I want to work with, and copy or move them into the new folder. (As a precaution I usually copy the files, keeping the original files intact.)

I then open up a terminal and cd into the directory containing the imagefiles I want to resize.

Next step is to create a subfolder for the resized images to be saved into.
(Hint: mkdir ./lowres   )

The last step is to run the convert command.

convert -resize 20% *.jpg lowres/Holiday2012_%03d.jpg


When the command is done, which may take some time depending of the number of files to convert, you will see that all the images are in the lowres -folder and are named Holiday_2012_000.jpg and so on.

The %03d in the convert command makes a three digit autoincremented number where %03d is.

Now the images have been resized and are more manageable when you want to upload to your facebook acoount.

No comments:

Post a Comment