在同一脚本中使用 GIMP 的批处理脚本以多种格式导出图像的最佳方法?
我正在尝试以不同格式创建GIMP图像的副本自动化,以便在网站上使用它们(使用图片元素,提供多个版本的图像以供兼容)。因此,我一直在尝试构建一个脚本来执行此操作,因此我不必手动导出每个图像,也可以使自己为图像定义自己的默认值。
到目前为止,我已经能够拼凑出一个完成我大多数目标的脚本:
(define (hugo-image-processing filename)
(
let* (
(image (car (gimp-file-load 1 (string-append filename ".xcf") (string-append filename ".xcf"))))
(drawable (car (gimp-image-get-active-layer image))))
(file-png-save-defaults 1 image drawable (string-append filename ".png") (string-append filename ".png"))
(file-heif-av1-save 1 image drawable (string-append filename ".avif") (string-append filename ".avif") 100 1)
(file-webp-save 1 image drawable (string-append filename ".webp") (string-append filename ".webp") 0 1 100 100 1 1 1 1 0 0 0 1 1)
(gimp-image-delete image)
)
)
这起作用,图像以预期格式导出,但是我注意到我的输出文件的大小根据图像为保存。在上述情况下,我的测试图像以139 kb的速度导出为AVIF文件,而我的WebP文件重76 kb。如果我交换订单,并在WebP文件之后保存AVIF文件,则WebP文件仍然包含76 kb,但是AVIF文件现在大小为58 kb。
如果一个人也移动file-png-save-defaults(尽管WebP在任何顺序上保持一致的76 KB),则可以看到这种行为。
我猜测文件 - 保存命令正在修改图像或可绘制的命令,但我还没有弄清楚为什么。我对方案的熟悉程度不太熟悉,因此,我对这一行为进行故障排除的能力是有限的。关于此问题的任何意见将不胜感激。
我运行此命令gimp-2.10 -i -b“(Hugo-Image Prococessing \“ Working \”)“ -b”(gimp-quit 0)”
调用脚本,我是在Windows 11上使用GIMP 2.10.30。
I am trying to automate creating copies of a GIMP image in different formats, in order to serve them on a website (Using the picture element, offering several versions of an image for compatibility). So I've been trying to build a script to do this so I don't have to manually export each image, as well as enable myself to define my own defaults for images.
So far, I have been able to cobble together a script that does accomplish most of my goals:
(define (hugo-image-processing filename)
(
let* (
(image (car (gimp-file-load 1 (string-append filename ".xcf") (string-append filename ".xcf"))))
(drawable (car (gimp-image-get-active-layer image))))
(file-png-save-defaults 1 image drawable (string-append filename ".png") (string-append filename ".png"))
(file-heif-av1-save 1 image drawable (string-append filename ".avif") (string-append filename ".avif") 100 1)
(file-webp-save 1 image drawable (string-append filename ".webp") (string-append filename ".webp") 0 1 100 100 1 1 1 1 0 0 0 1 1)
(gimp-image-delete image)
)
)
This works, and image are exported in expected formats, but I noticed that the size of my output files vary based on the order that the images are saved. In the above case, my test image exports as an AVIF file at 139 kB while my WebP file weighs in at 76 kB. If I swap the order, and save the AVIF file after the WebP file, the WebP file still contains 76 kB, but the AVIF file is now 58 kB in size.
This behavior can be seen if one moves the file-png-save-defaults as well (though WebP stays a consistent 76 kB in any order).
I'm guessing that the file--save commands are modifying either the image or the drawable, but I haven't quite figured out why. I'm not terribly familiar with Scheme, so my ability to troubleshoot this beyond observing this behavior is limited. Any input on this issue would be appreciated.
I run this command gimp-2.10 -i -b "(hugo-image-processing \"working\")" -b "(gimp-quit 0)"
to call the script, and I am using Gimp 2.10.30 on Windows 11.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据评论,问题似乎来自
file-webp-save
调用中的虚假“另存为动画”标志。可能是 2.10.30 中的一个错误,即使使用动画标志,我也无法在 2.10.24 中重现该错误。我使用以下代码测试了该问题:(
最后启动一个包含图像的 Gimp 窗口,而不是删除图像)。
编辑
fullname(...)
函数后,在 python-fu 控制台中复制粘贴,并作为savemulti("TestImage")
调用。当窗口出现时,您可以检查图层列表,看看是否有额外的图层......As per the comments, the problem appears to come from a spurious "save as animation" flag in the
file-webp-save
call. Possibly a bug in 2.10.30, that I cannot reproduce in my 2.10.24, even with the animation flag.I tested the problem with the following code:
(which at the end start a Gimp window with the image in it instead of deleting the image).
Copy-paste in the python-fu console, after editing the
fullname(...)
function, and invoke assavemulti("TestImage")
. When the windows comes up, you can check the Layers list and see if there are extra layers by any chance...