Question

I am using the following gimp script to rotate all images in a folder by 180° (the script is saved under ~/.gimp-2.8/scripts/batch-rotate.scm)

(define (batch-rotate pattern rotate-type)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))
             (gimp-image-rotate image rotate-type)
             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

I am calling the script like this:

gimp -i -b "(batch-rotate \"*.JPG\" 1)" -b '(gimp-quit 0)'

And I get the following error:

While parsing XMP metadata:
Error on line 85 char 1: End of element <exif:Flash> not expected in this context
While parsing XMP metadata:
Error on line 99 char 1: End of element <exif:Flash> not expected in this context

Metadata parasite seems to be corrupt
While parsing XMP metadata:
Error on line 85 char 1: End of element <exif:Flash> not expected in this context

** (file-jpeg:29145): WARNING **: JPEG - unable to decode XMP metadata packet
While parsing XMP metadata:
Error on line 85 char 1: End of element <exif:Flash> not expected in this context
While parsing XMP metadata:
Error on line 99 char 1: End of element <exif:Flash> not expected in this context

Metadata parasite seems to be corrupt
While parsing XMP metadata:
Error on line 85 char 1: End of element <exif:Flash> not expected in this context

** (file-jpeg:29149): WARNING **: JPEG - unable to decode XMP metadata packet
JPEG image-Warning: Premature end of JPEG file

While parsing XMP metadata:
Error on line 71 char 1: End of element <exif:Flash> not expected in this context
While parsing XMP metadata:
Error on line 85 char 1: End of element <exif:Flash> not expected in this context

Metadata parasite seems to be corrupt

... and so on until I interrupt it.

Could you help me out? What is going wrong here?

Was it helpful?

Solution

I didn't actually check your script code - but the way you are trying to call it is incorrect. Look what is displayed when you try your command line with "echo" instead of calling GIMP:

$ echo "(batch-rotate \"*.JPG\" 1)" -b '(gimp-quit 0)'
(batch-rotate "*.JPG" 1) -b (gimp-quit 0)

That is, the *.JPG pattern is enclosed in the quotes used to invoke the script, and bash does not expand it to the file list.

You may fight your way with the command line syntax, and then fix your script - there is some other error in it, else, it would just fail to find a file named "*.JPG" and end. However, I'd advise you to write your script in Python instead of script-fu. It is a higher level multi-purpose language, instead of a stripped down academic interpreter like the built-in script-fu, and can easily read all JPG files in a directory with a construct like:

import glob
for filename in directory + "/*.JPG":
   <code>

instead of trying to hack ways to pass list of files through the command line, and then hacking ways of extracting each filename from a list.

I am sorry to recommend another language, but unless you are already proficient in Scheme (the script-fu language), learning Python instead will be more useful to you in many other situations - including as scripting language for other programs, and including having other image libraries like PILLOW, pygame, vips, python-gegl, python-magick, python-opencv, all of which can rotate or flip images as well as the Python-GIMP bindings.

OTHER TIPS

Here's a native script that I've tested to correctly rotate a bunch of JPGs by 90 degrees:

  (define (batch-rotate90 pattern)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))

             (gimp-image-rotate image 0)

             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

The calling batch file is:

gimp-2.6 -i -b "(batch-rotate90 \"*.jpg\")" -b "(gimp-quit 0)"

Adjusting the 9th line in the script to (gimp-image-rotate image 1) should make the rotation 180 degrees (0 = 90 deg, 1 = 180 deg, 3 = 270 deg). Found on the website of Gregory Alan Hildstrom.

Since this script and the OP's seem to be effectively the same, it's possible that the OP's original image files were in fact corrupted (as indicated by the error shown, "Metadata parasite seems to be corrupt").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top