But it’s a bit more complex than the simplest of the batch conversions done using the mogrify command. The script itself is a one liner and you can use the convert command if you wish, so that’s the good part. Sometimes, this may not be what you want, and in such cases, you can resort to writing a little script. For example, if you use the mogrify command to batch convert a bunch of pictures to resize them, it overwrites the original images. However, if not used in conjunction with the format switch, it writes over the original image. In Imagemagick, the simplest way to batch transform a million images is by using the mogrify command. It prevents us from having to re-type a command a million times over. This part is obvious enough.īatch converting is a very useful process. This part simply takes the $file (a file) and resizes it using the resize switch and then chucks out a file called resized-$file. (The idea here is that all of the original files are in the Downloads folder, and we create a folder called newfolder to dump the transformed pictures.)Ĭonvert $file -resize 1275x1222 resized- $file Suppose further that the original files are in the Downloads folder. We have a bunch of *.jpg and we save them in a new folder called newfolder. Now, suppose that I want to save them in a completely different directory altogether. And it’s a one-liner! However, in this case, we save all the new files within the same folder as the old files.
The great part about this small piece of code is that it will batch convert as many pictures as you want. But this is not the case when we use the format switch (an exception to the rule). Typically, the distinction between mogrify and convert is that mogrify overwrites the original files. Here, the format switch prevents the images from being overwritten. We then tell the ImageMagick with the format switch to transform the image into a jpg image. Here, we’re telling the ImageMagick that there are lots of “.png” images to use each one with a “.png” extension.