Với gimp fu, tôi có thể lưu nội dung của một lớp (ít nhất, đó là cách tôi diễn giải định nghĩa của gimp_file_save
vì nó có tham số drawable
).Làm cách nào để lưu (xuất) tất cả các lớp với tập lệnh gimp của fu?
Bây giờ, tôi có kịch bản sau đây:
from gimpfu import *
def write_text():
width = 400
height = 100
img = gimp.Image(width, height, RGB)
img.disable_undo()
gimp.set_foreground((255, 100, 20))
gimp.set_background(( 0, 15, 40))
background_layer = gimp.Layer(
img,
'Background',
width,
height,
RGB_IMAGE,
100,
NORMAL_MODE)
img.add_layer(background_layer, 0)
background_layer.fill(BACKGROUND_FILL)
text_layer = pdb.gimp_text_fontname(
img,
None,
60,
40,
'Here is some text',
0,
True,
30,
PIXELS,
'Courier New'
)
drawable = pdb.gimp_image_active_drawable(img)
# Either export text layer ...
# pdb.gimp_file_save(img, drawable, '/temp/tq84_write_text.png', '?')
# .... or background layer:
pdb.gimp_file_save(img, background_layer, '/temp/tq84_write_text.png', '?')
register(
proc_name = 'tq84_write_text',
blurb = 'tq84_write_text',
help = 'Create some text',
author = 'Rene Nyffenegger',
copyright = 'Rene Nyffenegger',
date = '2014',
label = '<Toolbox>/Xtns/Languages/Python-Fu/_TQ84/_Text',
imagetypes = '',
params = [],
results = [],
function = write_text
)
main()
Khi tôi sử dụng pdb.gimp_file_save(img, drawable, '/temp/tq84_write_text.png', '?')
để lưu hình ảnh, Nó sẽ chỉ xuất khẩu "văn bản" lớp. Tuy nhiên, nếu tôi sử dụng pdb.gimp_file_save(img, background_layer, '/temp/tq84_write_text.png', '?')
, nó sẽ chỉ xuất nền. Vì vậy, làm thế nào tôi có thể xuất cả hai lớp vào một hình ảnh (như trình đơn File -> Export As
sẽ làm).
Bản sao của http://stackoverflow.com/questions/15482280/gimp-python-fu-exporting-file-only-exports-transparent-layer? –