【问题标题】:Getting Error( : 22091) >: argument 1 must be: number - GIMP Script-fu出现错误(:22091)>:参数 1 必须是:数字 - GIMP Script-fu
【发布时间】:2018-08-02 00:14:17
【问题描述】:

我有很多图像,大约 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) 使用 Gimp 这样做完全是矫枉过正,请参阅命令行实用程序,例如 ImageMagick,以及 2) 导致它的指令/API 调用的任何提示?
  • 另外,在你的代码中添加一些 gimp-message 调用来显示一些变量。如果图像未正确加载,潜在的罪魁祸首可能是“图像”
  • @xenoid re: 1) 你不知道 OP 的动机是什么,并且真的不应该在没有任何背景的情况下打折他们的方法。他们可能会为了学习 Scheme、Gimp 插件 API 或出于几乎无穷无尽的其他原因而进行此练习。
  • 我的经验(我一直在帮助人们使用 Gimp 和 Gimp 脚本编写超过 8 年)是,这些问题通常来自只考虑过 Gimp 和 don't know about the other tools 的人(一个例外是雇主要求 Gimp...)。

标签: scheme gimp script-fu


【解决方案1】:

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

但另一个问题是,虽然 gimp 文档说它返回一个 INT32(据我所知),但大多数 gimp api 调用实际上返回一个列表,即使列表中只有一个元素(参见 @987654321 @)。您需要在获取列表第一个元素的结果上调用 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))
        )
    )
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2012-07-15
    相关资源
    最近更新 更多