获取错误(:22091)>:参数1必须是:number - GIMP Script-fu

时间:2018-02-22 08:11:40

标签: scheme gimp script-fu

我有很多关于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)))))

1 个答案:

答案 0 :(得分:1)

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

但是另一个问题是,尽管gimp文档说它返回一个INT32(据我所知),但是即使列表中只有一个元素,大多数gimp api调用实际上也会返回一个列表(请参阅{{ 3}})。您需要在获取列表中第一个元素的结果上调用car,以便在scheme中使用它。

个人首选项,但您可能会发现缩进语法/作用域问题更加容易。

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