1

我正在使用以下 gimp 脚本将文件夹中的所有图像旋转 180°(脚本保存在 下~/.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)))))

我这样调用脚本:

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

我收到以下错误:

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

...等等,直到我打断它。

你能帮帮我吗?这里出了什么问题?

4

2 回答 2

0

我实际上并没有检查您的脚本代码 - 但您尝试调用它的方式不正确。查看当您尝试使用“echo”而不是调用 GIMP 的命令行时显示的内容:

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

也就是说,*.JPG模式包含在用于调用脚本的引号中,而 bash 不会将其扩展到文件列表中。

您可以使用命令行语法来解决问题,然后修复您的脚本 - 其中还有其他错误,否则,它将无法找到名为“*.JPG”的文件并结束。但是,我建议您使用 Python 而不是 script-fu 编写脚本。它是一种更高级别的多用途语言,而不是像内置 script-fu 那样精简的学术解释器,并且可以轻松读取目录中的所有 JPG 文件,其结构如下:

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

而不是试图破解通过命令行传递文件列表的方法,然后破解从列表中提取每个文件名的方法。

很抱歉推荐另一种语言,但除非您已经精通 Scheme(script-fu 语言),否则学习 Python 在许多其他情况下对您更有用 - 包括作为其他程序的脚本语言,包括拥有其他图像库,如 PILLOW、pygame、vips、python-gegl、python-magick、python-opencv,所有这些都可以旋转或翻转图像以及 Python-GIMP 绑定。

于 2014-05-10T22:19:05.873 回答
0

这是我测试过的本机脚本,可以将一堆 JPG 正确旋转 90 度:

  (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)))))

调用批处理文件是:

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

将脚本中的第 9 行调整为(gimp-image-rotate image 1)应使旋转 180 度(0 = 90 度,1 = 180 度,3 = 270 度)。在Gregory Alan Hildstrom 的网站上找到。

由于此脚本和 OP 似乎实际上相同,因此 OP 的原始图像文件实际上可能已损坏(如显示的错误所示,“元数据寄生虫似乎已损坏”)。

于 2016-08-19T04:50:18.737 回答