1

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?

09stephenb
  • 9,358
  • 15
  • 53
  • 91
TheChymera
  • 17,004
  • 14
  • 56
  • 86

2 Answers2

0

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.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • I am already quite proficient with python - it's just that i thought the scheme bindings were more native and that it would be simpler to just use shell to interface with everything. Can i write files under ```~/.gimp*/scripts/``` in python? – TheChymera May 10 '14 at 22:26
  • 1
    Python scripts lie under `~/.gimp*/plugins` and have to be marked as executable. The only two things needed are a call to "register" and to "main" - the former to register your procedure. Python bindings are actually more complete than scheme's: both can use the fully exported PDB, but from Python you can have byte-level access to pixel-regions - and there are some nice objects like Image, Layer. Layer Groups, built on top of the PDB values. – jsbueno May 12 '14 at 23:01
  • The calling code isn't wrong because the scheme function calls the globbing routine - it really is passing in a literal pattern not expecting the shell to do the expansion. – Julian Jan 24 '15 at 18:02
  • @Julian: instead of mere downvoting, would you care finding the O.P.'s problem with the scheme script them, since you seem to like the language? I reinstate my opinion that it is too low level, and has a hard-to-read and hard-to-write syntax, and new scripts should be done in Python instead, regardless of what is wrong in the original question. – jsbueno Jan 26 '15 at 13:27
  • 1
    Actually I couldn't my head around scheme either - I went down the python route for my problem. Your answer said "I didn't read the question but you have done this wrong" when they had not. If you would like to reword your answer to recommend python without criticising the "pass a pattern in and let the script do the globbing" approach I'll happily upvote it. – Julian Jan 26 '15 at 13:34
0

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").

Daniel R. Collins
  • 893
  • 1
  • 8
  • 22