Page 1 of 1
[SOLVED] hidden layers are appearing converting .xcf to .png
Posted: 2012-11-15T07:01:46-07:00
by spiderplant0
Hi, I have some .XCF images made by the GIMP that I wish to convert to .PNG on the command line. However I'm finding that ImageMagick is treating the hidden layers as visible and appearing in the output.
I'm using this ....
convert -alpha on -background none -layers merge t2.xcf t2.png
Here is a very simple example. The real images are more complex - eg - the layers that are hidden can be in arbitary positions.
https://skydrive.live.com/redir?resid=9 ... JktclXhhJk
Is there something I need to change to get this to work?
I'm on ImageMagick-6.8.0-4-Q16-windows-dll.exe on Windows 7 64-bit.
Thanks.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-15T10:02:38-07:00
by snibgo
I don't know whether IM takes any notice of whether layers are hidden.
You can get just one layer:
convert -alpha on -background none -layers merge t2.xcf[1] t2.png
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-15T11:14:02-07:00
by rich2005
I just found the same where no IM is involved. Using PCLOS & Gimp 2.8.2
An image with an alpha layer. A selection made and deleted (ie 'background deleted) but only one layer, no hidden layers.
Saved as an xcf and also exported as a png. Opened the png in a linux app 'fotoxx' no transparency and the background was restored.
Thought it was my error, repeated the export several times, same result. Open the xcf in Gimp, looks as it is supposed to. Must be a Gimp bug.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-15T12:57:01-07:00
by fmw42
I cannot even open your file in GIMP. I get the following error:
Opening '/Users/fred/Desktop/t2.xcf' failed: XCF error: unsupported XCF file version 3 encountered
This is on Mac OSX Snow Leopard and GIMP 2.6.11
I can convert to png in IM 6.8.0.4 Q16, but IM verbose information shows 3 layers and one gets all images when converted to PNG. However, the first layer is probably what you want
convert t2.xcf[0] t2.png
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-15T14:50:06-07:00
by spiderplant0
Thanks @fmw42, but I cant rely on the layer that I want being the top one as I have to deal with arbitary .xcf images which could have many layers, some hidden and some not. I am on GIMP 2.8 which may be why you cant open my file.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-15T16:01:47-07:00
by fmw42
spiderplant0 wrote:I am on GIMP 2.8 which may be why you cant open my file.
Poor design on GIMP's part if there file format is changing. Perhaps it is backward compatible.
Have you tried physically deleting those layers?
If you really think that the issue is IM not being able to distinguish hidden layers (whatever that means -- there but not enabled), then perhaps repost on the Developers forum and see if they are willing to look into it and/or fix it.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-16T01:27:30-07:00
by snibgo
For IM to respect Gimp's "visible" (the eye symbol that says whether a layer is to participate in the final image), it would need to replicate Gimp's composition modes: Normal, Dissolve, Lighten only, Screen, Dodge, and so on. And it would need to respect the opacity of each layer. And it would need to keep up with any changes the Gimp developers decided to make.
Personally, I think the IM developers have more useful work to do than replicating Gimp functionality. If you want a PNG from the visible layers of a multi-layered XCF, better to ask Gimp to do it, either interactively or in batch.
[EDIT: incorrect use of the Gimp word "active".]
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-16T05:52:28-07:00
by spiderplant0
Thanks snibgo. That makes sense. I will peruse the GIMP command line method. Its just a pity that IM documentation is not a bit clearer about it not really supporting .XCF. (Could have saved us some time).
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-16T20:24:10-07:00
by snibgo
[As this is an ImageMagick forum, not a Gimp forum, I hope the moderators will permit this post. Extraction from XCF is a common requirement that people try to solve with IM, and this may point them in the appropriate direction.]
Paste the following into a text file named savePng.scm in the Gimp scripts directory. (On my Windows 7 machine, the directory is %USERPROFILE%\.gimp-2.8\scripts\ .)
Code: Select all
(define (script-fu-save-png filename)
(let*
(
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY)))
(fileparts "")
(pngname "")
)
(set! fileparts (strbreakup filename "."))
(set! fileparts (butlast fileparts))
(set! pngname (string-append (unbreakupstr fileparts ".") ".png"))
(file-png-save-defaults RUN-NONINTERACTIVE image drawable pngname pngname)
(gimp-image-delete image)
(gimp-quit 0)
)
)
(script-fu-register
"script-fu-save-png" ;funtion name
"Save as Png" ;menu label
"Saves an image as PNG." ;description
"Alan Gibson" ;author
"copyright 2012, Alan Gibson" ;copyright notice
"November 16, 2012" ;date created
"" ;works on all image types
SF-STRING "filename" "Filename"
)
(script-fu-menu-register "script-fu-save-png" "<Image>/File")
This gives you a menu option (under "File") as well as a function you can run in batch.
To run in batch, use the following Windows 7 commands. Adjust as necessary for other shells.
Code: Select all
set gb=c:\Program Files\gimp 2\bin\gimp-console-2.8.exe
"%gb%" -i -b "(script-fu-save-png \"test.xcf\")"
Note that gb points to the
console version of Gimp. It just saves me typing time.
Disclaimer: no guarantees. If this destroys your images or your computer, tough luck.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T10:02:44-07:00
by spiderplant0
Thanks snibgo. That mostly worked. However it is not converting images exactly like the GIMP does . It seems to be creating an image that is the size of the extents of the largest layer rather than clipping everything to the size of the image.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T11:15:06-07:00
by snibgo
For EXPAND-AS-NECESSARY, substitute CLIP-TO-IMAGE. (The other possibility is CLIP-TO-BOTTOM-LAYER.)
Maybe the IM developers could use this method to pull the merged visible layers from Gimp, via IM's delegate system. Not ideal, as it needs a script in a Gimp directory. Maybe the important bits from the script could be jammed into a single command line.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T11:47:58-07:00
by snibgo
Yes, this works, as a single command line to merge visible layers from test.xcf to p.png:
Code: Select all
"c:\Program Files\gimp 2\bin\gimp-console-2.8.exe" -i -b "(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE \"test.xcf\" \"test.xcf\"))) (drawable (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY)))) (file-png-save-defaults RUN-NONINTERACTIVE image drawable \"p.png\" \"p.png\") (gimp-image-delete image) (gimp-quit 0))"
So there is no need for a script, and it could (in principle) be put in the delegates file.
[EDIT: typo in second "test.xcf".]
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T12:24:43-07:00
by spiderplant0
Thanks, modifying the savePng.scm worked for me
Also, FYI, I tried your command line version. I assumed the command shows you converting 2 XCF files, so I deleted tests.xcf and deleted one p.png but it gave this error...
Code: Select all
E:\>"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b "(let
* ((image (car (gimp-file-load RUN-NONINTERACTIVE \"t2.xcf\"))) (drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))) (file-png-save
-defaults RUN-NONINTERACTIVE image drawable \"p.png\") (gimp-image-delete image) (gimp-quit 0))"
(gimp-console-2.8.exe:1840): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
RMA-path-blend: image-type contains unrecognizable parts:'RGB*, GREY*'
batch command experienced an execution error:
Error: ( : 1) Invalid number of arguments for gimp-file-load (expected 3 but received 2)
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T13:05:41-07:00
by snibgo
No, my command was right, except that "tests.xcf" should read "test.xcf" (but it still works!). Source and destination filename must each appear twice.
Re: hidden layers are appearing when converting .xcf to .png
Posted: 2012-11-17T13:50:13-07:00
by spiderplant0
Works for me now.