首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取错误(:22091) >:参数1必须为: number - GIMP Script-fu

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

Stack Overflow用户
提问于 2018-02-22 16:11:40
回答 1查看 302关注 0票数 2

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

代码语言:javascript
复制
Error: ( : 22091) >: argument 1 must be: number

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

代码语言:javascript
复制
(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)))))
EN

回答 1

Stack Overflow用户

发布于 2018-08-06 22:13:20

您有两个问题,第一个问题是您没有分配imageWidthimageHeight。封装fetch image width/height调用的括号不会有任何用处。因此,当计算(> imageWidth imageHeight)时,imageWidth/imageHeight不是数字。要分配返回值,(imageWidth) (gimp-image-width image)应为(imageWidth (gimp-image-width image))

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

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

代码语言:javascript
复制
(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))
        )
    )
)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48922441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档