Par*_*rto 80 gimp image-processing
我遇到了一种情况,我在 Gimp 中有一个具有多层的图像。现在,我想将每个图层作为单独的图像(最好是 PNG 格式)自动导出到某个文件夹中。
这可能吗?
长方法:隐藏除一层之外的所有图层,裁剪您想要的部分,导出图像。隐藏保存的图层,取消隐藏另一个图层,裁剪部分,导出。重复。对于大约 20 层的图像来说有点麻烦。
Tho*_*ner 113
如果 PNG 是一种可接受的输出格式,一种选择是将其导出为 Open Raster (.ora),这是一种分层图像文件的开放规范。
将图像导出为开放光栅 (.ora)
File -> Export As ...
myfile.ora
myfile.ora
以存档形式打开,使用类似file-roller
或的程序7zip
。
在 Ubuntu 上:
$ file-roller myfile.ora
$ # note, later version of file-roller on ubuntu hard-code file suffixes,
# and refuse to open ".ora" files, work around by renaming the file to ".zip"
$ ln -s myfile.ora myfile.ora.zip
$ file-roller myfile.ora.zip
Run Code Online (Sandbox Code Playgroud)
或者
$ unzip myfile.ora
Run Code Online (Sandbox Code Playgroud)
您的所有图层都将是 png 图像/data
,提取它们并随意使用。
小智 52
你也可以试试这个插件,Export Layers。我已经用 png 格式测试过它并且它有效。您只需选择文件夹和格式,即可获得所有图层,每个图层都在其自己的文件中。
小智 10
首先,您不需要任何插件。即使你不需要裁剪任何东西。几个简单的步骤。
就是这样。现在您可以简单地将该图层导出为任何格式。
可以将图像导出为动画 GIF。这会将每个图层保存为 GIF 中的单独帧。
然后,ImageMagick 命令 convert -coalesce ./myfile.gif outfile%05d.png
会将帧提取为 PNG 图像。
ThorSummoner 的答案最好的一点是它引起了人们对 OpenRaster 导出插件的注意,事实证明该插件存在于文件中file-openraster.py
GIMP 安装的文件中。
通过阅读其代码(并在内置程序浏览器的帮助下),我能够确定 GIMP XCF 的图层可以通过界面中的“过滤器”>“Python-fu”>“控制台”保存到单个 PNG,并将以下内容输入到内置的 Python 解释器中:
import os
# If you have multiple images open, you may need to adjust
img = gimp.image_list()[0]
savefn = gimp.pdb['file-png-save-defaults']
outpath = "/home/$USER/Pictures" # (or r"C:\Users\$USER\Pictures", etc)
for lay in img.layers:
# Even if your layer names contain spaces, not a problem
outname = lay.name + ".png"
savefn(img, lay, os.path.join(outpath, outname), outname)
# type an extra newline to exit the indented block
Run Code Online (Sandbox Code Playgroud)
您将看到图像窗口状态栏中的进度表开始快速浏览所有图层,将每个图层写入同名的 PNG 文件中,无论您指定为outpath
. (它必须已经存在,否则os.makedirs(outpath, exist_ok=True)
在循环之前添加一个。)
如果任何图层名称相同,那就是一个问题,因为这会很高兴地覆盖任何以前编写的文件。警告 GIMPtor。
编辑:如果您确实有同名图层,您可以轻松忽略这些名称,而是在编号文件中写出图层。只需将上面的最后一个循环替换为:
for n, lay in enumerate(img.layers):
outname = f"Layer {n:03}.png"
savefn(img, lay, os.path.join(outpath, outname), outname)
Run Code Online (Sandbox Code Playgroud)
这会将图层写入名为“Layer 000.png”到“Layer 999.png”的 PNG 文件中(或者存在多个图层,如果少于 1000 个)。
如果 Gimp 的 Python 版本不支持 f 字符串(Python 3.6+),则这完全等效:
outname = "Layer {0:03}.png".format(n)
Run Code Online (Sandbox Code Playgroud)
小智 5
我想你可以尝试找到一些东西ImageMagick
:apt-get install imagemagick
。它似乎能够处理 XCF 格式,您可以使用命令中的 [N] 以 png 格式导出图层,其中 N 是图层的级别。
来源:http : //www.imagemagick.org/discourse-server/viewtopic.php?f=1& t= 17603
ImageMagick 读取模组:http : //www.imagemagick.org/Usage/files/#read_mods
归档时间: |
|
查看次数: |
148374 次 |
最近记录: |