Search code examples
coldfusioniptc

IPTC data in coldfusion 9


I am using coldfusion's imageGetIPTCMetadata() function to get the iptc keywords.

I used Photomechanics to insert some keywords in a hierarchical fashion like this

Personnel   |   Appointments   |   Assistant Chief of General Staff (ACGS), Personnel  |  Ranks  |  Royal Marine  |  Colour Sergeant (CSgt), Personnel | Ranks | Royal Navy | Chief Petty Officer (CPO), Personnel|Ranks|Army|Field Marshall (Fd Marshall) (FM)

But after I call the method in my CFC I get this -

How can I get the keywords with a delimeter or something so that I can reuse them in my code.

enter image description here


Solution

  • I found the solution here:

    <cfparam name="URL.source" default="xmp-asset.jpg">
    <cffile action="readbinary" file="#ExpandPath(URL.source)#" variable="data">
    <!-- encode the binary data to hex -->
    <cfset hex_data = BinaryEncode(data,"hex") />
    <!-- string indicating beginning of packet '<x:xmpmeta' -->
    <cfset xmp_string_begin = "3C783A786D706D657461" />
    <!-- string indicating end of packet '</x:xmpmeta>' -->
    <cfset xmp_string_end = "3C2F783A786D706D6574613E" />
    <!-- find the starting index in the hex string -->
    <cfset idx_start = FindNoCase(xmp_string_begin,hex_data) />
    <!-- find the ending index in the hex string -->
    <cfset idx_end = FindNoCase(xmp_string_end,hex_data,idx_start) + Len(xmp_string_end) />
    <!-- using the start and end indices, extract the xmp packet -->
    <cfset xmp_hex = Mid(hex_data,idx_start,Evaluate(idx_end-idx_start)) />
    <!-- convert the hex to readable characters -->
    <cfset xmp_string = ToString(BinaryDecode(xmp_hex,"hex")) />
    <!-- parse the xml string to and xml structure -->
    <cfset xmp_xml = XmlParse(xmp_string) />
    <cfcontent type="text/xml">
    <cfoutput>#xmp_string#</cfoutput>
    

    Now I can get the entire XMP xml and do all I want to do with the data there.