Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script-FU: Batch rotate script
#1
Question 
I am trying to write a batch rotate script, to rotate a number of images by an angle which is passed to the script.
I have the following, which is successfully registered in Gimp:
Code:
(script-fu-register
  "script-fu-batch_arbitrary_rotate"
  "Batch Rotation"
  ""
  ""
  ""
  ""
  "*"
)

(script-fu-menu-register "script-fu-batch_arbitrary_rotate" "<Image>/Tools/My scripts")

(
define (script-fu-batch_arbitrary_rotate pattern inDegrees)
  (let*
    (
      (filelist (cadr (file-glob pattern 1)))
    )
    (while
      (not (null? filelist))
      (let*
        (
          (filename (car filelist))
          (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
          (radians ( / (* inDegrees 4 (atan 1.0)) 180)) ;converts angle <inDegrees> to radians
          (gimp-item-transform-rotate image radians FALSE 150 150)
          (drawable (car (gimp-image-get-active-layer image)))
          (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
        )
        (set! filelist (cdr filelist))
      )
    )
  )
)

This is called in terminal by (to rotate each image by 35 degrees and save):
Code:
gimp -i -b '(script-fu-batch_arbitrary_rotate "*.png" 35)' -b '(gimp-quit 0)'

The terminal output states: "batch command executed successfully", but the images are not rotated. The files' properties suggest that no operations were performed.

I have racked my brains over this; can anyone help with the above script?
Reply
#2
Not a script-fu expert, but it looks like gimp-item-transform-rotate expects a layer/channel/path, not an image. If you want to rotate the image use gimp-image-rotate.
Reply
#3
Thank you for your reply. I looked at gimp-image-rotate, but Procedure Browser states that the rotate-type parameter only accepts ROTATE-90 (0), ROTATE-180 (1), ROTATE-270 (2).
I want to be able rotate the images by an arbitrary angle.
Reply
#4
(02-04-2019, 05:48 AM)Ofnuts Wrote: Not a script-fu expert, but it looks like gimp-item-transform-rotate expects a layer/channel/path, not an image. If you want to rotate the image use gimp-image-rotate.
Sorry - misread the problem. Missed that the problem was about rotating the whole image.

I guess the answer is to use gimp-item-transform-rotate on each of the layers in the image. Use gimp-image-get-layers to get a list of the layers in the image and iterate through them.
Reply
#5
(02-04-2019, 05:35 PM)programmer_ceds Wrote:
(02-04-2019, 05:48 AM)Ofnuts Wrote: Not a script-fu expert, but it looks like gimp-item-transform-rotate expects a layer/channel/path, not an image. If you want to rotate the image use gimp-image-rotate.
Sorry - misread the problem. Missed that the problem was about rotating the whole image.

I guess the answer is to use gimp-item-transform-rotate on each of the layers in the image. Use gimp-image-get-layers to get a list of the layers in the image and iterate through them.

Each image has only 1 layer.
Reply
#6
Yes, I read the gimp-image-rotate description a bit too fast Smile But yes, you likely have to rotate layers (in any case the save API also deals with layers and not images).
Reply


Forum Jump: