I have a Python Gimp question.  I don't know if it belongs on the user or
developer list, but my feeling is that the people with the knowledge are
more likely to read this list.  Let me know if this is the wrong list to
post to.

I have written a script to create PNG and XCF versions of an image I want to
save.  I have a certain layer whose visibility I want to turn off before I
save the PNG but I also want the XCF to give me more editting power if I
want to alter the image later.  I have this working fairly well, but the
problem is that when my script finishes, I am looking at the flattened PNG
version of the image.  At that point, I would need to close the PNG and
re-open the XCF if I want to edit the file.  This is less than ideal.  I
think it could be solved by simply doing one undo step after saving the PNG
(since flattening was the last thing I did), but I don't see in the
procedural database a way to undo from a script.  Is there a way to save a
flattened PNG and then save an unflattened XCF of the same image and leave
the XCF open?

Here is my code:

from gimpfu import *

def my_save(img, drawable):
    ind = find_graph_ind(img)

    if ind:
        img.layers[ind].visible = False
        filename = save_as(initialdir=folder, initialfile=new_name)#<--- get
filename from Tk dialog
        print('filename = ' + filename)
        if filename:
            pne, ext = os.path.splitext(filename)
            xcf_path = pne+'.xcf'
            pdb.gimp_xcf_save(1, img, drawable, xcf_path, xcf_path)
            flat_layer = pdb.gimp_image_flatten(img)
            pdb.gimp_file_save(img, flat_layer, filename, filename)#<---
filename ends in .png
            #pdb.file_png_save(img, flat_layer, filename, filename, \
            #                  0, 0, 0, 0, 0, \
            #                  1, 1)


Gimp-developer mailing list

Reply via email to