It is currently Fri Sep 25, 2026 12:09 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: saving an XCF without destroing as PNG
PostPosted: Mon Feb 13, 2017 12:05 pm  (#1) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
GIMP Version: 2.8.14
Operating System: Windows
GIMP Experience: Intermediate Level



Hallo,
Is there a command to save an XCF as PNG in PYTHON, without destroing the XCF by flattening it?

I see at this moment only this possibility all in a Python-script :

create a new image,
copy layers out of the original into the new image,
flatten that new image
save it as PNG (has only ONE layer!)
remove it ...


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Mon Feb 13, 2017 12:14 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
You could use gimp-layer-new-from-visible to create a new layer that reflects how the image looks and save that as .PNG then delete the temporary layer.

Kevin


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Mon Feb 13, 2017 12:52 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Isn'it even simpler?
With your multilayer .xcf image open on your display, click on "export" (as .png).
Gimp will provide internally to flatten before exporting, but your image is still on the display with all its layers.
Am I wrong?

_________________
"Where am I ?"


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Mon Feb 13, 2017 2:04 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
paynekj wrote:
You could use gimp-layer-new-from-visible to create a new layer that reflects how the image looks and save that as .PNG then delete the temporary layer.

Kevin

+1
In fact you don't need to add it to the image:

layer = pdb.gimp_layer_new_from_visible(image, image, 'foo')
pdb.file_png_save_defaults(image, layer, '/tmp/x.png', '/tmp/x.png')

But to save memory you can do:
gimp.delete(layer)

_________________
Image


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Tue Feb 14, 2017 12:36 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
dinasset wrote:
Isn'it even simpler?
With your multilayer .xcf image open on your display, click on "export" (as .png).
Gimp will provide internally to flatten before exporting, but your image is still on the display with all its layers.
Am I wrong?

Sorry for my stupid post, I did not read correctly you were asking how to do it in a filter, I thought you were talking of interactive actions.

_________________
"Where am I ?"


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Tue Feb 14, 2017 8:17 am  (#6) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
dissanet, no problem ;-)

Indeed, I need to save an XCF with a lot of layers in a plugin (te make gif's after moving or discarding layers, see my CHECKER project).


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Tue Feb 14, 2017 8:24 am  (#7) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
ofnuts wrote:
paynekj wrote:
You could use gimp-layer-new-from-visible to create a new layer that reflects how the image looks and save that as .PNG then delete the temporary layer.

Kevin

+1
In fact you don't need to add it to the image:

layer = pdb.gimp_layer_new_from_visible(image, image, 'foo')
pdb.file_png_save_defaults(image, layer, '/tmp/x.png', '/tmp/x.png')

But to save memory you can do:
gimp.delete(layer)


Thanks!
Works and it is so easy!
Peter

EDIT:
maybe (as I did) add a self in the def-head ;)
def saveThisStep( picturePrefix, Step):
    image = gimp.image_list()[0]
    layer = pdb.gimp_layer_new_from_visible(image, image, "foo")
    thisName = picturePrefix + str(Step) + ".png"
    pdb.file_png_save_defaults(image, layer, thisName, thisName )
    gimp.delete(layer)
    result =  "This Picture " + thisName + " created"
    return result


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Tue Feb 14, 2017 8:15 pm  (#8) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 8471
Location: On the other side of your screen
I don't save everything as an xcf which I regret at times but when I do - I save as an xcf first then export as a png.
Also you can flatten and export as a png. Then undo flatten and save as an xcf.
Gimp will always give you the option to save as an xcf when you go to close the image.
Don't know of a filter that can do it.

_________________
Image
Free Fun Photo Editing & resources
Poems from the Lord
Gimp Newby
Gimp version 3.2.4 and GMIC-Qt 4.0.2 OS :- Windows 10 Home 64


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Wed Feb 15, 2017 1:52 am  (#9) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
Sallyanne, from out the Gimp UI, it is no problem at all,
the problem WAS how to do that from out a Python plugin (Pygtk UI) ..

Hm, undo flatten, never thaugt about that ... thanks

Peter


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Wed Feb 15, 2017 3:11 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Hmmm Come to think of it I don't see much difference with you other question. Use "New from visible", etc. If you want a background color, just add a temporary background layer.

_________________
Image


Top
 Post subject: Re: saving an XCF without destroing as PNG
PostPosted: Wed Feb 15, 2017 3:36 pm  (#11) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
ofnuts wrote:
Hmmm Come to think of it I don't see much difference with you other question. Use "New from visible", etc. If you want a background color, just add a temporary background layer.


Oh look, above, the script is all I need ;)


Top
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group