以下脚本将通过Gimp CLI接口调用,它将当前目录中所有PNG的颜色模式更改为索引:
(define (script-fu-batch-indexify pattern)
(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))))
(gimp-image-convert-indexed image NO-DITHER MAKE-PALETTE 256 0 0 "")
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))此脚本运行良好,但它要求不对当前目录中的每个PNG进行索引。当它找到一个索引的PNG时,它将立即中止。我的目的是让它跳过索引的PNG。我认为最好的方法是这样做:
(define (script-fu-batch-indexify pattern num-cols)
(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))))
(unless (gimp-drawable-is-indexed image) ; Now it does not work anymore...
(gimp-image-convert-indexed image NO-DITHER MAKE-PALETTE num-cols 0 0 "")
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image)))
(set! filelist (cdr filelist)))))但是这样做会阻止脚本工作!它执行时没有任何错误,也没有索引任何未索引的PNG。我尝试使用if,结果是一样的。那么,我到底搞错了什么呢?
(我使用的是Gimp 2.8.22,而不是Linux Mint 19.3。)
发布于 2020-05-08 00:50:29
脚本不是以方案通常编写的方式编写的:我们非常努力地避免set!操作,您所做的可以使用递归而不是while循环来实现-在函数式编程风格中,这是推荐的方式。
话虽如此,我没有看到你的代码有任何明显的缺陷,你确定这个表达式对于任何图像来说都是假的吗?
(gimp-drawable-is-indexed image)试着在unless表达式之前打印上面的结果,让我们看看它显示了什么。从终端启动Gimp并查看控制台:
(print (gimp-drawable-is-indexed image))
(unless (gimp-drawable-is-indexed image)发布于 2020-05-11 03:38:47
按如下方式使用打印:
(display (string-append "\n Indexed:" (number->string (car (gimp-drawable-is-indexed drawable))) "< \n"))(display ..)创建一个字符串首先在PDB中查找gimp-drawable-is-indexed,返回int32 => (数字->字符串,但所有函数都返回列表=> (car (..
(gimp-drawable-is-indexed .)需要图层而不是图像。https://stackoverflow.com/questions/61662823
复制相似问题