TheJoe.it Into the (open) source

5Jun/122

Resize multiple images in one go

Caution!

This article was written in the 2012, there may have been some developments in the subject matter.
If in doubt please leave a comment in the bottom of the article.
Thanks.

gimp_imagick

Resize Images, since the photo editing programs have become part of the routine of the average, is a task as simple as trivial. It is used especially for smaller size is available save bandwidth on the transfer of the file: a smaller image will load faster and also to use the pictures on the web is not required high resolution. The problem arises when we have a considerable number of images to be resized, open them one by one can become quite long and tedious.

One of the solutions is "David's Batch Processor", a plugin for Gimp that allows you to run some filters on multiple images, including the "Resize" to resize.

"David's Batch Processor" can be fun to discover, and can certainly speed up the work that otherwise we would hand, but compared to other programs is slow. I know the fastest way to resize multiple images in one go is the command line. ImageMagick is a small yet powerful command line tool (obtained via the web as added library to PHP). ImageMagick is a program that includes several commands, Today we see a couple.

Convert

The command "convert" converts the source image and creates a copy. At the end we will have the initial image processing and the converted image. With "convert" You can not overwrite an image.

Now let's see how it is possible change the size of an image:

convert -geometry 1024x 1.jpg 1_mod.jpg

This command resizes the long side image "1.jpg" a 1024px, maintaining unchanged proportions.

for i in *.jpg; do convert -geometry 1024x $i thumb-$i; done

This one command performs the same job, but converts all images with estensione ".jpg" 1024px to the side.

for i in *.jpg; do convert -scale 50% $i thumb-$i; done

This one command uses the argument "scale" in place of "geometry". The argument "scale" is used together with the percentage of reduction / magnification image. In this case the image will be halved.

convert originale.jpg originale.png

Should be noted that "convert" can also be used to change the file extension (will always create a copy without overwriting).

Mogrify

The command "mogrify" is virtually identical to the command "convert", the difference is that it will create a copy of the original, but overwrite the source image. Eye so you do not overwrite if it is not exactly what you want to do.

In a few minutes we finished to resize our images, and we did not do the job manually. A real godsend.

About

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

Comments (2) Trackbacks (0)
  1. Hello I want to know how I can use the command mogrify to resize a file 800×400 a 800×800 maintaining the aspect ratio.

    Thanks

    • I do not think you understand. Your starting image is 800×400. You will scalarne size (both), because it modifies only the aspect ratio is not respected.
      Maybe you're going to “cut off” part of the image, in this case you can cut it to 400×400 and then oversize it 800×800. Obviously you have a poor quality when done.


Leave a comment

No trackbacks yet.