有人可以给我一个脚本,我需要在GIMP的Script.Fu中将许多* .jpeg文件批量转换为* .png吗?
目前我花费太多时间手动导出每张图片,这是浪费时间。
我现在无法安装任何东西,因此无法使用替代应用程序。
答案 0 :(得分:0)
真正的解决方案是使用ImageMagicks转换,就像magick convert some.jpeg some.png
一样简单。必须有一个“便携式”版本,您可以使用USB密钥。
否则使用Gimp,一种不需要新脚本的手动方式,因为它使用现有脚本:
File>Open
第一个JPEG File>Open as layers
更多Jpegs。您可以在一次调用中选择几个/所有jpeg(实际数量主要受可用RAM限制)。完成此操作后,您将在同一图像中堆叠许多Jpeg File>Export all layers
,确保您使用的名称模式以.png
结尾(脚本附带的文档说明了其工作原理)。答案 1 :(得分:0)
好吧,经过多次试验和错误,我终于找到了如何仅使用 GIMP 将一种文件格式转换为另一种文件格式的方法。
这是用于转换为 PNG 的 Script-Fu 脚本:
(
let* ((filename "{{filename}}")
(output "{{output}}")
(image (car (gimp-file-load 1 filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(file-png-save-defaults 1 image drawable output output)
)
其中 {{filename}}
是需要转换的输入文件(例如 jpeg 文件),{{output}}
是您需要的输出文件(它可以只是相同的文件名,但带有 PNG扩展)
如何运行它:它可能可以改进
gimp -i -n -f -d --batch "{{one-line script-fu}}"
您可以在 GIMP online documentation 中找到有关命令行选项的更多信息。
需要改的地方是{{one-line script-fu}}
,而且必须是……一行!您可以可能使用 cmd 在一个文件中完成所有这些操作(如果您使用 Windows),但对我来说使用 Python 更容易,所以这里是它的脚本:
import subprocess, os
def convert_to_png(file_dds):
#Loads the command to run gimp cli (second code block)
#Note: remove "{{one-line script-fu}}" and leave one space after the --batch
with open("gimp-convert.bat", "r") as f:
main_script = f.read()
#Prepares the Script-Fu script to be run, replacing necessary file names and makes it one-line (the firs code block)
with open("gimp-convert-png.fu", "r") as f:
script = f.read().replace("\n", " ").replace("{{filename}}", file_dds) \
.replace("{{output}}", file_dds[:-3]+"PNG").replace("\\", "\\\\").replace("\"", "\\\"")
subprocess.run(main_script + " \"" + script + "\" --batch \"(gimp-quit 1)\"",
cwd = os.getcwd(),
shell = True)
您应该将文件转换为 PNG!
我的纹理高档项目需要这个,您可以在下面找到所有代码here。
使用 GIMP 2.10 测试