How do I save (export) all layers with gimp's script fu?

南楼画角 提交于 2019-12-03 06:37:50

What is done internally, even by GIMP file-expoerter plug-ins for all formnats is: duplicate the image, merge all visible layers, them save the resulting drawable.

This is easier, and take less resources than it sounds. Effectively you just have to replace your save line

pdb.gimp_file_save(img, background_layer, '/temp/tq84_write_text.png', '?')

by

new_image = pdb.gimp_image_duplicate(img)
layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE)
pdb.gimp_file_save(new_img, layer, '/temp/tq84_write_text.png', '?')
pdb.gimp_image_delete(new_image)

(The last call just "deletes" the new image from program memory, freeing up the resources, of course)

I have found out that if you pass None as the drawable argument to gimp_xcf_save(), GIMP (at least version 2.8) will save all layers of the image to the XCF file:

pdb.gimp_xcf_save(0, image, None, 'file.xcf', 'file.xcf')

What I found easiest was to flatten the image then just save using the first layer:

img.flatten()
pdb.gimp_file_save(img, img.layers[0], 'image.jpg', '?')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!