I'm trying to find a way, either from a linux command line application, or through something accessible from PHP (MagickWand?) that would read a PNG file and return the layers information of the file.
Maybe there are different ways to name so to be specific, by layers I mean basically the same info I would get by opening the file with Fireworks and checking the layers window.
Is this something ImageMagick can do? If not is there a way, even through libpng? I'd rather not but if necessary I have no problem writing a small C application that would do this, given I know how to proceed.
How do I list the layers of a PNG?
Re: How do I list the layers of a PNG?
I made a screen shot from Fireworks of what I mean: http://www.strangeelement.com/PNGLayers.png. In it, Fireworks lists layers (likely a proxy for something else that they simply call layers but aren't really, information I would use if I can get it), one of which contains 4 objects with a name, likely an available coordinate, size and fill color.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How do I list the layers of a PNG?
PNG does not have layers. Layers in Photoshop and I guess in Fireworks are proprietary formats that are kept internally until the file is saved and then usually flattened. Photoshop format saves layers as that is there own format. IM can get the layers from Photoshop saved format, but I believe that when you saved the PNG, the layers were flattened. In IM, the layers are like gif frames, namely a multi-image format. You can make PNG layers in IM, but other applications such as Photoshop and Fireworks probably won't save the layers to those formats.strangeelement wrote:I made a screen shot from Fireworks of what I mean: http://www.strangeelement.com/PNGLayers.png. In it, Fireworks lists layers (likely a proxy for something else that they simply call layers but aren't really, information I would use if I can get it), one of which contains 4 objects with a name, likely an available coordinate, size and fill color.
Anthony or Magick may be able to be more specific and correct me if I am wrong here.
Re: How do I list the layers of a PNG?
If Fireworks does save the layers in a proprietary format, it does save them in the file since if I close and open the file again, the layer and objects information is still present.
Of course if it is a proprietary format there's not much I can do. This seems to be the case since if I open the same PNG in GIMP, neither the layers nor the objects (i.e. the named rectangles) are identified. The file opens up as a flattened image.
Also in GIMP, adding a rectangle, which in Fireworks creates a unique object, is flattened in the image.
So I guess what I was hoping to do is impossible with PNG. I tried with convert -verbose using a PSD and it pretty much does what I need.
I was probably taken on the wrong track by the special way Fireworks deals with PNGs. At least I can accomplish the same thing with the PSD format.
Thanks a lot for the help!
Rich.
Of course if it is a proprietary format there's not much I can do. This seems to be the case since if I open the same PNG in GIMP, neither the layers nor the objects (i.e. the named rectangles) are identified. The file opens up as a flattened image.
Also in GIMP, adding a rectangle, which in Fireworks creates a unique object, is flattened in the image.
So I guess what I was hoping to do is impossible with PNG. I tried with convert -verbose using a PSD and it pretty much does what I need.
I was probably taken on the wrong track by the special way Fireworks deals with PNGs. At least I can accomplish the same thing with the PSD format.
Thanks a lot for the help!
Rich.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How do I list the layers of a PNG?
If this is a PNG, then that is interesting as the information must be in the file as you say. You may want to post an example and ask if anyone can see if they can determine if that multi-layer data is there and accessible.If Fireworks does save the layers in a proprietary format, it does save them in the file since if I close and open the file again, the layer and objects information is still present.
If it is a true muli-layer file and not just proprietary information in the header, then you can do:
identify fireworksfile.png
and it should give you a line for each "layer" as it does with muli-frame gifs.
For example
identify morph_anim.gif
morph_anim.gif[0] GIF 112x112 112x112+0+0 8-bit PseudoClass 256c 11kb
morph_anim.gif[1] GIF 112x112 112x112+0+0 8-bit PseudoClass 256c 11kb
Note IM can same muli-frame files using -adjoin
see
http://www.imagemagick.org/script/comma ... php#adjoin
However, there are some formats that this does not work (although the IM docs say to use +adjoin to force it) and this seems to be the case for png in IM.
convert rose: rose: rose: rose.png
identify rose.png
rose.png PNG 70x46 70x46+0+0 8-bit DirectClass 6.78kb
Only one frame, not 3
convert rose: rose: rose: -adjoin rose.png
identify rose.png
rose.png PNG 70x46 70x46+0+0 8-bit DirectClass 6.78kb
Only one frame, not 3
convert rose: rose: rose: +adjoin rose.png
identify rose.png
rose.png PNG 70x46 70x46+0+0 8-bit DirectClass 6.78kb
Only one frame, not 3
CORRECTION: actually what it did was to make rose-0.png rose-1.png and rose-2.png
Not sure if this is a bug or not. Not sure what +adjoin means by "join images into a single multi-image file."
Last edited by fmw42 on 2008-10-21T12:04:23-07:00, edited 1 time in total.
Re: How do I list the layers of a PNG?
In my tests saving the PNG as PSD I noticed something obvious I missed: Fireworks has a distinct PNG format. It can either save as flattened PNG or Fireworks PNG. The latter uses private chunks of information that save the same information as is in the bitmap information as vector elements.
Adobe's site explains it in this document: http://www.adobe.com/support/fireworks/ ... sav02.html.
Adobe's site explains it in this document: http://www.adobe.com/support/fireworks/ ... sav02.html.
So it does make sense that IM cannot read this information, unless Adobe releases it some day.Technically speaking, Macromedia chose PNG (which stands for Portable Network Graphics) as the native file format for Fireworks because the format has both open source and proprietary characteristics. In most applications, the default file format is proprietary, meaning other applications can't open it. PNG, however, is an open source file format. Some graphic applications and browsers can open PNGs too. However, they can only read the graphical portion of a PNG's file information. Fireworks PNG files contain a second "chunk" of data that other applications can't read, which contains proprietary information about things like slicing, interactivity, and any Live Effects that may have been applied.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How do I list the layers of a PNG?
For completeness...
This is what I posted to the same request on magick-users mail list.
On that note I would like to remind users that IM even adds a small amount of propriety meta-data to its PNG image output. It is just a tiny extra bit of data holding the current virtual-canvas size information of the image. Normally PNG does not contain this information, limiting itself to a image offset only.
On the other hand that image offset can be positive or negative, unlike GIF images
This is what I posted to the same request on magick-users mail list.
Obviously this has proved correct. As the extra info is in proprietary meta-data.A PNG file does not have multiple layers.
It does have offset information for layers but that is the extent of it.
On that note I would like to remind users that IM even adds a small amount of propriety meta-data to its PNG image output. It is just a tiny extra bit of data holding the current virtual-canvas size information of the image. Normally PNG does not contain this information, limiting itself to a image offset only.
On the other hand that image offset can be positive or negative, unlike GIF images
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/