Google Groups Home
Help | Sign in
Read XMP (photoshop) metadate from file
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Klaus Jensen  
View profile  
 More options Jun 10 2006, 4:14 pm
Newsgroups: microsoft.public.dotnet.framework.drawing
From: "Klaus Jensen" <spamm...@burninhell.com>
Date: Sat, 10 Jun 2006 22:14:18 +0200
Local: Sat, Jun 10 2006 4:14 pm
Subject: Read XMP (photoshop) metadate from file
Hi!

I need to access the XMP-metadata stored by Photoshop in jpeg-files. I have
been looking for a solution for hours on google, google groups etc et c

Fields can be found here: http://www.portfoliofaq.com/pfaq/FAQ00311.htm
And Adobe (who invented the format as far as I can tell) has created and
SDK: http://partners.adobe.com/public/developer/xmp/sdk/index.html#gs

Unfortunately there is only some sort of C-source in expat_config.h (NOT
C#), which I have NO clue what to do with...

I have also found a commercial .net component which will read the metadata
(http://www.atalasoft.com/products/dotImage/) but is is priced at 999$ - and
I only need to read a bit of metadata from an open format, so 999$ seems
like overkill. ;)

I have tried to view the jpeg-files in a text-editor, and the meta-data is
very neatly formatted, example:

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>com.apple.print.PageFormat.PMHorizontalRes</key>
[etc etc]

What I need is some code to access the metadata. Any help will be greatly
appreciated.

Thanks in advance

Klaus Jensen, MCSD


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Klaus Jensen  
View profile  
 More options Jun 10 2006, 7:08 pm
Newsgroups: microsoft.public.dotnet.framework.drawing
From: "Klaus Jensen" <spamm...@burninhell.com>
Date: Sun, 11 Jun 2006 01:08:20 +0200
Local: Sat, Jun 10 2006 7:08 pm
Subject: Re: Read XMP (photoshop) metadate from file

"Klaus Jensen" <spamm...@burninhell.com> wrote in message

news:uZJgzpMjGHA.4504@TK2MSFTNGP05.phx.gbl...

Allow me to answer my own question. :)

I did manage to get the xml in the file using a hack, and then I had access
to the xml-metadata.

It is certainly NOT very pretty code, but it will give another developer
facing a similar challenge something to work with. :)

Public Class ImageMetaData

Public CaptionWriter As String

Public AuthorsPosition As String

Public Credit As String

Public Source As String

Public Category As String

Public Colormode As String

Public ICCProfile As String

Public DateCreated As String

Public Urgency As String

Public Instructions As String

Public Headline As String

Public Description As String

Public Sub New(ByVal filename As String)

Dim xmpXmlDoc As String

xmpXmlDoc = GetXmpXmlDocFromImage(filename)

LoadDoc(xmpXmlDoc)

End Sub

Private Sub LoadDoc(ByVal xmpXmlDoc As String)

Dim xr As New Xml.XmlDocument

Dim nl As Xml.XmlNodeList

Try

xr.LoadXml(xmpXmlDoc)

Catch ex As Exception

Throw New ApplicationException("An error occured while loading XML metadata
from image. The error was: " & ex.Message)

End Try

Try

xr.LoadXml(xmpXmlDoc)

nl = xr.GetElementsByTagName("dc:description")

Me.Description = nl.Item(0).ChildNodes(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:CaptionWriter")

Me.CaptionWriter = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:AuthorsPosition")

Me.AuthorsPosition = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Credit")

Me.Credit = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Source")

Me.Source = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Category")

Me.Category = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:ColorMode")

Me.Colormode = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:ICCProfile")

Me.ICCProfile = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:DateCreated")

Me.DateCreated = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Urgency")

Me.Urgency = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Instructions")

Me.Instructions = nl.Item(0).InnerText()

nl = xr.GetElementsByTagName("photoshop:Headline")

Me.Headline = nl.Item(0).InnerText()

Catch ex As Exception

Throw New ApplicationException("Error occured while readning meta-data from
image. The error was: " & ex.Message)

Finally

nl = Nothing

xr = Nothing

End Try

End Sub

Public Overrides Function Tostring() As String

Dim output

output += "CaptionWriter: " & Me.CaptionWriter & vbCrLf

output += "AuthorsPosition: " & Me.AuthorsPosition & vbCrLf

output += "Credit: " & Me.Credit & vbCrLf

output += "Source: " & Me.Source & vbCrLf

output += "Category: " & Me.Category & vbCrLf

output += "Colormode: " & Me.Colormode & vbCrLf

output += "ICCProfile: " & Me.ICCProfile & vbCrLf

output += "DateCreated: " & Me.DateCreated & vbCrLf

output += "Urgency: " & Me.Urgency & vbCrLf

output += "Instructions: " & Me.Instructions & vbCrLf

output += "Headline: " & Me.Headline & vbCrLf

output += "Description: " & Me.Description & vbCrLf

Return output

End Function

Public Shared Function GetXmpXmlDocFromImage(ByVal filename As String) As
String

Dim contents As String

Dim xmlPart As String

Dim beginCapture As String = "<x:xmpmeta"

Dim endCapture As String = "</x:xmpmeta>"

Dim beginPos, endPos As Integer

Dim sr As New System.IO.StreamReader(filename)

contents = sr.ReadToEnd

Debug.Write(contents.Length & " chars" & vbCrLf)

sr.Close()

sr = Nothing

beginPos = InStr(contents, beginCapture, CompareMethod.Text) - 1

endPos = InStr(contents, endCapture, CompareMethod.Text)

Debug.Write("xml found at pos: " & beginPos.ToString & " - " &
endPos.ToString)

xmlPart = contents.Substring(beginPos, (endPos - beginPos) +
endCapture.Length)

Debug.Write("Xml len: " & xmlPart.Length.ToString)

Return xmlPart

End Function

End Class


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google