Batch images rotation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
korr4k
Posts: 2
Joined: 2019-10-03T06:16:03-07:00
Authentication code: 1152

Batch images rotation

Post by korr4k »

Hy everyone, I already asked for help on Gimp forum and I was reccomended to try out ImageMagick to solve my problem. I'll copy my question from there:

**************************************************************************************************************************************************************************

For a project that I'm working on, I need to rotate a batch of images (50k+), the good news is that the rotation that I need is constant and Gimp works perfectly for that.

I tried with a single image and everything that I need is to do is to open the .jpg, use the rotation tool with the following options: 0.2°, cubic interpolation and crop with the original image ratio. After that with just another crop around the image borders the process is complete.

Clearly I can't do that for 50k+ images and I need some automated way. I saw that there is the possibility in Gimp to import external tools/scripts or to work via console.

With the premise that I know how to use Python, what do you think is the best way for me? Plug-ins like Bimb only rotate the images for fixed amount of ° and I'm worried that I can't set parameters such as the interpolation. Can I do that via scripts or the options are very basic for them too?

I tried so search on the web for suggestions but the results are old and maybe something new is already available

**************************************************************************************************************************************************************************
Do you think that the same operations are possible with IM? I originally went for Gimp because the rotation tool has already built in the option to "crop with aspect" which is essential for me and also the possibility to set a specific interpolation method
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch images rotation

Post by snibgo »

korr4k wrote:Do you think that the same operations are possible with IM?
Yes. The basic command could be:

Code: Select all

magick in.jpg -filter XXX -rotate 0.2 out.jpg
... where XXX is a named filter. As you may know, you shouldn't use JPG unless you really have to.

You probably need a shell loop to process all the files.
snibgo's IM pages: im.snibgo.com
korr4k
Posts: 2
Joined: 2019-10-03T06:16:03-07:00
Authentication code: 1152

Re: Batch images rotation

Post by korr4k »

snibgo wrote: 2019-10-03T06:39:56-07:00
korr4k wrote:Do you think that the same operations are possible with IM?
Yes. The basic command could be:

Code: Select all

magick in.jpg -filter XXX -rotate 0.2 out.jpg
... where XXX is a named filter. As you may know, you shouldn't use JPG unless you really have to.

You probably need a shell loop to process all the files.
The images I'm working with are from the AVA dataset and they are all jpg, I'm planning to save the new ones in png to "save" their original quality. I'll try to look into IM scripts
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch images rotation

Post by fmw42 »

If the rotation is the same for all images, you can do that with mogrify in ImageMagick on a whole folder of files. It loops through each image in the folder. Alternately you can write a script to loop over each image and do that. Cubic Convolution would be -filter Catrom. If you know Python, then you could do the script looping and processing in Python Wand. See https://imagemagick.org/Usage/basics/#mogrify and http://docs.wand-py.org/en/0.5.7/

To rotate with a filter, you need to use

-filter Catrom +distort SRT "0.2"

See https://imagemagick.org/Usage/distorts/#srt

You can crop maintaining aspect ratio using

-crop 3:2

for example. See https://imagemagick.org/script/command- ... p#geometry and https://stackoverflow.com/questions/212 ... pect-ratio


Please clarify your crop requirements. You may be interested in the inner trim option to to -trim. See https://imagemagick.org/discourse-serve ... =4&t=35579
Post Reply