0

I am trying to get keywords added to a PNG image file in Photoshop using Java.

I tried this method using the imageio in Java:

http://johnbokma.com/java/obtaining-image-metadata.html

However, all I get is the following:

Format name: javax_imageio_png_1.0
<javax_imageio_png_1.0>
    <IHDR width="128" height="128" bitDepth="8" colorType="RGBAlpha" compressionMethod="deflate" filterMethod="adaptive" interlaceMethod="none"/>
    <cHRM whitePointX="31269" whitePointY="32899" redX="63999" redY="33001" greenX="30000" greenY="60000" blueX="15000" blueY="5999"/>
    <iCCP profileName="Photoshop ICC profile" compressionMethod="deflate"/>
    <pHYs pixelsPerUnitXAxis="2835" pixelsPerUnitYAxis="2835" unitSpecifier="meter"/>
</javax_imageio_png_1.0>
Format name: javax_imageio_1.0
<javax_imageio_1.0>
    <Chroma>
        <ColorSpaceType name="RGB"/>
        <NumChannels value="4"/>
        <BlackIsZero value="TRUE"/>
    </Chroma>
    <Compression>
        <CompressionTypeName value="deflate"/>
        <Lossless value="TRUE"/>
        <NumProgressiveScans value="1"/>
    </Compression>
    <Data>
        <PlanarConfiguration value="PixelInterleaved"/>
        <SampleFormat value="UnsignedIntegral"/>
        <BitsPerSample value="8 8 8 8"/>
    </Data>
    <Dimension>
        <PixelAspectRatio value="1.0"/>
        <ImageOrientation value="Normal"/>
        <HorizontalPixelSize value="0.35273367"/>
        <VerticalPixelSize value="0.35273367"/>
    </Dimension>
    <Transparency>
        <Alpha value="nonpremultipled"/>
    </Transparency>
</javax_imageio_1.0>

Nothing about the keywords added...

Am I not doing it right? Is this library not getting the XMP metadata?

EDIT:

Although I would have preferred to know if the standard library could read the metadata, I gave the pngj library a try. But that gave me the following error:

Exception in thread "main" ar.com.hjg.pngj.PngjExceptionInternal: this should not happen
    at ar.com.hjg.pngj.PngIDatChunkInputStream.read(PngIDatChunkInputStream.java:117)
    at ar.com.hjg.pngj.PngReader.readSkippingAllRows(PngReader.java:777)
    at se.expertinfo.ditaplugin.ImageMetadata.showChunks(ImageMetadata.java:105)
    at se.expertinfo.ditaplugin.DitaPlugin.printImageMetadata(DitaPlugin.java:33)
    at se.expertinfo.ditaplugin.DitaPlugin.main(DitaPlugin.java:24)
Java Result: 1

If I comment out the pngr.readSkippingAllRows(); (which may for all I know make the method useless?) I get the following result:

filename=architecture3.png ImageInfo [cols=128, rows=128, bitDepth=8, channels=4, bitspPixel=32, bytesPixel=4, bytesPerRow=512, samplesPerRow=512, samplesPerRowP=512, alpha=true, greyscale=false, indexed=false, packed=false]
ChunkList: read: 5
 Read:
chunk id= IHDR (len=13 offset=8) c=PngChunkIHDR G=0
chunk id= pHYs (len=9 offset=33) c=PngChunkPHYS G=1
chunk id= iCCP (len=2639 offset=54) c=PngChunkICCP G=1
chunk id= cHRM (len=32 offset=2705) c=PngChunkCHRM G=1
chunk id= IDAT (len=25329 offset=2749) c=PngChunkIDAT G=4

BUILD SUCCESSFUL (total time: 0 seconds)

I.e. nothing about the keywords in there...

BTW: Here is the metadata set in Photoshop. The same metadata appears under the IPTC tab...

Metadata in Photoshop

EDIT 2: In response to leonbloy:

Added Title and Author, but still no output (Getting the IEND though):

filename=architecture3.png ImageInfo [cols=128, rows=128, bitDepth=8, channels=4, bitspPixel=32, bytesPixel=4, bytesPerRow=512, samplesPerRow=512, samplesPerRowP=512, alpha=true, greyscale=false, indexed=false, packed=false] ChunkList: read: 6 Read: chunk id= IHDR (len=13 offset=8) c=PngChunkIHDR G=0 chunk id= pHYs (len=9 offset=33) c=PngChunkPHYS G=1 chunk id= iCCP (len=2639 offset=54) c=PngChunkICCP G=1 chunk id= cHRM (len=32 offset=2705) c=PngChunkCHRM G=1 chunk id= IDAT (len=25329 offset=2749) c=PngChunkIDAT G=4 chunk id= IEND (len=0 offset=28090) c=PngChunkIEND G=6

I can see the added metadata in Adobe Bridge...

EDIT 3:

Well, I have no explanation for it, but all of a sudden the javax.imageio library works fine! I'm getting all the metadata as expected, and I don't even know of doing any changes to it.

I'm just missing one thing - I would have liked to be able to get metadata in key/value pairs, like Product=Apple, but I cannot seem to find any such way of adding metadata. Is this available in some way, and how would I get to it?

Anders
  • 12,556
  • 24
  • 104
  • 151
  • Are you sure the image have more metadata? To peek into it, use this nice tool: http://entropymine.com/jason/tweakpng/ – leonbloy Dec 03 '12 at 12:22
  • I'm sure it's there when I look at it in Photoshop. It's added in the dialog "File info" (powered by XMP). Unfortunately I cannot use the tool you suggest, because I'm on a Mac, not Windows. – Anders Dec 03 '12 at 12:28
  • YOu can try also my PNGJ http://code.google.com/p/pngj : here's a [sample](http://code.google.com/p/pngj/source/browse/pnjg/src/ar/com/hjg/pngj/test/SampleShowChunks.java) that lists all chunks – leonbloy Dec 03 '12 at 12:42
  • I will the issue tonight, in the meanwhile, try replacing `pngr.readSkippingAllRows();` with `pngr.readRow(pngr.imgInfo.rows-1);` – leonbloy Dec 03 '12 at 18:46
  • Ok, thanks, but that gave me almost the exact same results as when I just commented it out above, with a couple of small differences. Still nothing about the keyword metadata though... – Anders Dec 03 '12 at 18:51
  • IT must show the IEND chunk as last one. If that's so, the chunks were read ok, and your metadata is not inside the PNG. Try write some data (author, title) in the above dialog, save the PNG, and open it (preferably in other computer) and see if it appears. – leonbloy Dec 03 '12 at 18:59
  • possible duplicate of [Is XMP metadata supported in PNG images?](http://stackoverflow.com/questions/21316655/is-xmp-metadata-supported-in-png-images) – Paul Sweatte Aug 08 '14 at 19:16

0 Answers0