Search code examples
command-linegimpgimpfu

How do I rotate an image from a console using GIMP?


I am trying to run GIMP using console commands. All I want it to do is rotate an image 90 degrees. I added GIMP to my environmental variables so that I can call it from a console window. I also put the picture I want to rotate in my root console directory to make it easy to open.

I read the GIMP Batch Mode guide and came up with this command:

gimp-2.10 -i -b '(gimp-image-rotate plot.png 0)' -b '(gimp-quit)'

The "0" after "plot.png" is supposed to tell it to rotate 90 degrees. This opens a GIMP output window and outputs two messages saying "batch command executed successfully". However, it never rotates the image.

Any idea why the command I have entered is not working?


Solution

  • gimp-image-rotate rotates a loaded image and not a file that contains an image. So you have to

    1. obtain an image by loading it from a file (see the gimp-file-load or gimp-file-{type}-load calls),
    2. rotate the image,
    3. save the result (gimp-file-{type}-save (caution: these calls save a layer, not the whole image)).

    But for simple manipulations you are better off using a toolbox designed to be called from scripts such as ImageMagick:

    magick mogrify -rotate 90 plot.png