1

I'm trying to read DPI from a PSD file with JAVA. I'm using ImageIO (incl TwelveMonkeys extensions) and/or Apache Commons Imaging. Unfortunately can't manage it to go (JPG, PNG and TIFF works fine)

here is the file information from photoshop:

    <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:xmp="http://ns.adobe.com/xap/1.0/">
         <xmp:CreatorTool>Adobe Photoshop CS6 (Macintosh)</xmp:CreatorTool>
         <xmp:CreateDate>2017-05-18T10:47:41+02:00</xmp:CreateDate>
         <xmp:MetadataDate>2017-05-18T11:17:54+02:00</xmp:MetadataDate>
         <xmp:ModifyDate>2017-05-18T11:17:54+02:00</xmp:ModifyDate>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <dc:format>application/vnd.adobe.photoshop</dc:format>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
            xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#">
         <xmpMM:InstanceID>xmp.iid:96F5C1320B206811822AAF07DD778819</xmpMM:InstanceID>
         <xmpMM:DocumentID>xmp.did:0180117407206811822AAF07DD778819</xmpMM:DocumentID>
         <xmpMM:OriginalDocumentID>xmp.did:0180117407206811822AAF07DD778819</xmpMM:OriginalDocumentID>
         <xmpMM:History>
            <rdf:Seq>
               <rdf:li rdf:parseType="Resource">
                  <stEvt:action>created</stEvt:action>
                  <stEvt:instanceID>xmp.iid:0180117407206811822AAF07DD778819</stEvt:instanceID>
                  <stEvt:when>2017-05-18T10:47:41+02:00</stEvt:when>
                  <stEvt:softwareAgent>Adobe Photoshop CS6 (Macintosh)</stEvt:softwareAgent>
               </rdf:li>
               <rdf:li rdf:parseType="Resource">
                  <stEvt:action>saved</stEvt:action>
                  <stEvt:instanceID>xmp.iid:0280117407206811822AAF07DD778819</stEvt:instanceID>
                  <stEvt:when>2017-05-18T10:48:03+02:00</stEvt:when>
                  <stEvt:softwareAgent>Adobe Photoshop CS6 (Macintosh)</stEvt:softwareAgent>
                  <stEvt:changed>/</stEvt:changed>
               </rdf:li>
               <rdf:li rdf:parseType="Resource">
                  <stEvt:action>saved</stEvt:action>
                  <stEvt:instanceID>xmp.iid:96F5C1320B206811822AAF07DD778819</stEvt:instanceID>
                  <stEvt:when>2017-05-18T11:17:54+02:00</stEvt:when>
                  <stEvt:softwareAgent>Adobe Photoshop CS6 (Macintosh)</stEvt:softwareAgent>
                  <stEvt:changed>/</stEvt:changed>
               </rdf:li>
            </rdf:Seq>
         </xmpMM:History>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
         <photoshop:ColorMode>3</photoshop:ColorMode>
         <photoshop:ICCProfile>sRGB IEC61966-2.1</photoshop:ICCProfile>
         <photoshop:TextLayers>
            <rdf:Bag>
               <rdf:li rdf:parseType="Resource">
                  <photoshop:LayerName>OK PSD 2557x2200px 150dpi RGB</photoshop:LayerName>
                  <photoshop:LayerText>OK PSD 2557x2200px 150dpi RGB</photoshop:LayerText>
               </rdf:li>
            </rdf:Bag>
         </photoshop:TextLayers>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
         <tiff:Orientation>1</tiff:Orientation>
         <tiff:XResolution>1500000/10000</tiff:XResolution>
         <tiff:YResolution>1500000/10000</tiff:YResolution>
         <tiff:ResolutionUnit>2</tiff:ResolutionUnit>
      </rdf:Description>
      <rdf:Description rdf:about=""
            xmlns:exif="http://ns.adobe.com/exif/1.0/">
         <exif:ColorSpace>1</exif:ColorSpace>
         <exif:PixelXDimension>2557</exif:PixelXDimension>
         <exif:PixelYDimension>2200</exif:PixelYDimension>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

it would be cool if i could get the part:

<tiff:XResolution>1500000/10000</tiff:XResolution>
<tiff:YResolution>1500000/10000</tiff:YResolution>

i'm reading dimension like this:

final IIOMetadata metadata = reader.get().getImageMetadata(0);
final IIOMetadataNode standardTree = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
final IIOMetadataNode dimension = (IIOMetadataNode) standardTree.getElementsByTagName("Dimension").item(0);

thx

rome
  • 476
  • 1
  • 9
  • 19
  • There aren't any free tools for reading psd files (and PSD is **not** designed for [interchange](http://blogs.adobe.com/jnack/2009/05/some_thoughts_about_the_psd_format.html)). – Elliott Frisch May 18 '17 at 21:59
  • @rome What dimension do you get by using the code above then? Note that the TwelveMonkeys `PSDImageReader` gets its dimension metadata from the PSD ResolutionInfo structure though, *not* the XMP metadata (but these *should* be in sync). – Harald K May 19 '17 at 08:37
  • @ElliottFrisch I believe you are wrong: [TwelveMonkeys PSD reader plugin for ImageIO](https://github.com/haraldk/TwelveMonkeys#psd---adobe-photoshop-document). There are others as well. I do agree it's not the best choice for file interchange though. ;-) – Harald K May 19 '17 at 08:43
  • @haraldK this code reads infos from other file types. i try to get "HorizontalPixelSize" there. it is supposed to be a chain. if one method is not successful, try with another... can you show me, how the correct way would be? – rome May 19 '17 at 08:57
  • @rome Ouch.. It turns out there's a stupid bug in the `PSDMetadata` class, that prevents the ResolutionInfo from ever being reported... :-( It's easy to fix though. Would you please report this as a bug in the [issue tracker](https://github.com/haraldk/TwelveMonkeys/issues)? Your code is fine. – Harald K May 19 '17 at 09:57
  • @haraldK Should have read "there aren't any good free and reliable tools I know of (and requests for third-party libraries are off topic) for reading PSD files" – Elliott Frisch May 19 '17 at 10:00
  • @ElliottFrisch I guess I can't make any good arguments about the reliability part right now... :-P – Harald K May 19 '17 at 10:10
  • @haraldK uuuh, that's bad news o.O because i need to get it to go today. do you know of a workaround? i will report the bug over the weekend, today i need to figure it out somehow. does it make sence to clone repository, fix, and build a new version? thx in advance – rome May 19 '17 at 10:13
  • @rome Yes, you could do that (clone & build). Just change PSDMetata.java line 630 from `if (!resolutionInfos.hasNext()) {` to `if (resolutionInfos.hasNext()) {` (as I said, stupid bug). – Harald K May 19 '17 at 10:16
  • @haraldK not big of a deal... will hopefully work out, otherwise i'm dead :-) – rome May 19 '17 at 10:18
  • @haraldK thx, works fine after fix. sorry, still haven't reported a bug, but i will do it! thx again haraldK – rome May 22 '17 at 05:51
  • No worries. I added it, just so I wouldn't forget. – Harald K May 22 '17 at 06:08

0 Answers0