我有很多图像,大约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)))))发布于 2018-08-06 22:13:20
您有两个问题,第一个问题是您没有分配imageWidth或imageHeight。封装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,它获取列表的第一个元素,以便在方案中使用它。
个人偏好,但您可能会发现缩进的语法/范围问题更容易看到。
(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))
)
)
)https://stackoverflow.com/questions/48922441
复制相似问题