2

我有很多大约 100 张的图像,我需要使用缩放因子调整所有图像的大小。但是,当我运行脚本时,它向我显示以下错误

Error: ( : 22091) >: argument 1 must be: number

我不是 Script-Fu 方面的专家,所以我找不到任何可以帮助我的资源。以下是我的脚本,任何帮助将不胜感激。

(define (batch-resize pattern scaleFactor)
(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)))
(imageWidth) (gimp-image-width image)
(imageHeight) (gimp-image-height image))
(let * ((imageFactor 1))
(if (> imageWidth imageHeight) 
((set! imageFactor (/ imageWidth scaleFactor))) ((set! imageFactor (/ imageHeight scaleFactor))))
(set! imageWidth (/ imageWidth imageFactor))
(set! imageHeight (/ imageHeight imageFactor)))
(gimp-image-scale-full image imageWidth imageHeight INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
4

1 回答 1

1

你有两个问题,第一个是你没有分配imageWidthimageHeight. 封装获取图像宽度/高度调用的括号无处可去。因此,在(> imageWidth imageHeight)评估时,imageWidth/imageHeight 不是数字。 (imageWidth) (gimp-image-width image)应该是(imageWidth (gimp-image-width image))分配返回值。

但另一个问题是,虽然 gimp 文档说它返回一个 INT32(据我所知),但大多数 gimp api 调用实际上返回一个列表,即使列表中只有一个元素(参见教程/文档)。您需要调用car获取列表第一个元素的结果,以便在方案中使用它。

个人偏好,但您可能会发现缩进更容易看到语法/范围问题。

(define (batch-resize pattern scaleFactor)
    (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)))
                    (imageWidth (car (gimp-image-width image)))
                    (imageHeight (car (gimp-image-height image)))
                )
                (let * ((imageFactor 1))
                    (if (> imageWidth imageHeight) 
                        ((set! imageFactor (/ imageWidth scaleFactor)))
                        ((set! imageFactor (/ imageHeight scaleFactor)))
                    )
                    (set! imageWidth (/ imageWidth imageFactor))
                    (set! imageHeight (/ imageHeight imageFactor))
                )
                (gimp-image-scale-full image imageWidth imageHeight INTERPOLATION-CUBIC)
                (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
                (gimp-image-delete image)
            )
            (set! filelist (cdr filelist))
        )
    )
)
于 2018-08-06T14:13:20.390 回答