用jpeg编写XMP元数据(使用PHP)-使用单个或多个rdf:Description块 [英] Writing XMP Metadata in jpeg (with PHP) - Using Single or Multiple rdf:Description blocks

查看:121
本文介绍了用jpeg编写XMP元数据(使用PHP)-使用单个或多个rdf:Description块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 PHP_JPEG_Metadata_Toolkit 修改代码,以便可以读写XMP使用PHP正确读取jpeg文件的数据.当前,jpeg文件(由工具包保存时)在Adobe Photoshop&由于XMP块而桥接.

I am attempting to modify the code from PHP_JPEG_Metadata_Toolkit so that I can read and write XMP data correctly for jpeg files using PHP. Currently, the jpeg files (when saved by the Toolkit) give errors with Adobe Photoshop & Bridge because of the XMP block.

我有两种查看Photoshop使用的XMP RDF架构的方法.首先是Photoshop实际上保存在jpg中的内容,并且我正在导入. Photoshop对所有内容使用单个rdf:Description块.它在块本身内引发许多模式标识符(URL),并且为许多元数据字段添加值.接下来是都柏林Core,Photoshop,Iptc4xmpCore等的标记块,但所有标记块都集中在一个Description标记中.

There are two ways I'm seeing the XMP RDF schema used by Photoshop. The first is what Photoshop is actually saving in the jpg and which I am importing. Photoshop uses a single rdf:Description block for everything. It throws many schema identifiers (urls) within the block itself PLUS adds values for many metadata fields. Then following are tag blocks for Dublin Core, Photoshop, Iptc4xmpCore, etc., but all lumped together within a single Description tag.

第二个是按照 RDF的XMP文档(其中规定按照惯例,给定模式中的所有属性,并且只有该模式,都在单个rdf:Description元素中列出.")

The second is the neatly formatted Metadata displayed inside of Photoshop "File Info" that follows the XMP documentation for RDF (which states "By convention, all properties from a given schema, and only that schema, are listed within a single rdf:Description element.")

通过使用Photoshop实际发送的示例(所有在rdf:Description下的所有内容)的示例,我已经能够解决Photoshop在由工具包编辑时给出错误的问题

I've been able to fix the problem with Photoshop giving errors when edited by the Toolkit by following the example of what Photoshop actually sends (everything under one rdf:Description)

两个问题:知道为什么Photoshop保存的XMP元数据与程序中显示的不同吗?并且...当它可以很好地将所有输出混杂在一个rdf:Description中时,为什么还要花时间将其输出格式设置为RDF规格呢?我不熟悉所有这些内容,因此任何指导都将不胜感激.

Two questions: Any idea why Photoshop saving the XMP metadata different from what it shows inside the program? And … Why should I spend the time to format my output to the RDF specs when it works nicely all jumbled together in a single rdf:Description? I am new to working with all this and so any guidance would be appreciated.

这些示例已经过编辑,因此您可以更轻松地仅看到格式上的差异-请原谅仅是由于编辑而造成的两者之间的内容差异.

These examples are edited so you can more easily see the formatting differences only - please forgive content discrepancies between the two that are just from editing.

这是我实际上从Photoshop收到的信息(已编辑):

Here is what I am actually receiving from Photoshop (edited):

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 
  <rdf:Description rdf:about="" 
        xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" 
        xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" 
        xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" 
        xmlns:xmp="http://ns.adobe.com/xap/1.0/" 
        xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/" 
        xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" 
        xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" 
        xmlns:dc="http://purl.org/dc/elements/1.1/"             
        xmpMM:DocumentID="xmp.did:8808E8B6139411E3A70AB29CEEC8FF6C"
        xmpMM:InstanceID="xmp.iid:0071BBEF4517E311BCBCC2DF868D188C"
        xmpMM:OriginalDocumentID="" 
        xmp:CreatorTool="(PHP JPEG Metadata Toolkit v1.12)" 
        xmp:MetadataDate="2013-09-06T15:44:49-07:00" 
        xmp:ModifyDate="2013-09-06T15:44:49-07:00" 
        xmp:CreateDate="2013-09-06T15:22:46-07:00" 
        xmpRights:Marked="True" 
        xmpRights:WebStatement="MY WEB ADDRESS" 
        Iptc4xmpCore:IntellectualGenre="" 
        photoshop:Instructions="OOOInstructions" 
        photoshop:Headline="OOOHeadline" 
        photoshop:CaptionWriter="MY NAME" 
        dc:format="image/jpeg"> 
        <xmpMM:DerivedFrom stRef:instanceID="6B5F4850BB0819F254E40401F67ACAC9" 
        <stRef:documentID="6B5F4850BB0819F254E40401F67ACAC9"/> 

    <xmpRights:UsageTerms> 
        <rdf:Alt> 
            <rdf:li xml:lang="x-default">MY INFO HERE</rdf:li> 
        </rdf:Alt> 
    </xmpRights:UsageTerms> 

    <dc:description> 
        <rdf:Alt> 
        <rdf:li xml:lang="x-default">OOODescription
        </rdf:li> 
        </rdf:Alt> 
    </dc:description> 

  </rdf:Description> 
</rdf:RDF> 

这是Photoshops格式良好的视图(已编辑)

Here is Photoshops nicely formatted view (edited)

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
        xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
        xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
        xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#">
     <xmpMM:DocumentID>xmp.did: … ETC…</xmpMM:DocumentID>
     <xmpMM:InstanceID>xmp.iid: …ETC… </xmpMM:InstanceID>
     <xmpMM:OriginalDocumentID/>
     <xmpMM:DerivedFrom rdf:parseType="Resource">
        <stRef:instanceID>6B5F4850BB0819F254E40401F67ACAC9</stRef:instanceID>
        <stRef:documentID>6B5F4850BB0819F254E40401F67ACAC9</stRef:documentID>
     </xmpMM:DerivedFrom>
  </rdf:Description>

  <rdf:Description rdf:about=""
        xmlns:xmp="http://ns.adobe.com/xap/1.0/">
     <xmp:CreatorTool>Adobe Photoshop CS6 (Windows)</xmp:CreatorTool>
     <xmp:MetadataDate>2013-09-06T15:44:49-07:00</xmp:MetadataDate>
     <xmp:ModifyDate>2013-09-06T15:44:49-07:00</xmp:ModifyDate>
     <xmp:CreateDate>2013-09-06T15:22:46-07:00</xmp:CreateDate>
  </rdf:Description>

  <rdf:Description rdf:about=""
        xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/">
     <xmpRights:Marked>True</xmpRights:Marked>
     <xmpRights:WebStatement>MY WEB ADDRESS</xmpRights:WebStatement>
     <xmpRights:UsageTerms>
        <rdf:Alt>
           <rdf:li xml:lang="x-default">MY INFO HERE</rdf:li>
        </rdf:Alt>
     </xmpRights:UsageTerms>
  </rdf:Description>

  <rdf:Description rdf:about=""
        xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/">
     <Iptc4xmpCore:IntellectualGenre/>
  </rdf:Description>

  <rdf:Description rdf:about=""
        xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
     <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
     <photoshop:Headline>OOOHeadline</photoshop:Headline>
     <photoshop:CaptionWriter>OOO </photoshop:CaptionWriter>
  </rdf:Description>

  <rdf:Description rdf:about=""
        xmlns:dc="http://purl.org/dc/elements/1.1/">
     <dc:format>image/jpeg</dc:format>
     <dc:description>
        <rdf:Alt>
           <rdf:li xml:lang="x-default">OOODescription</rdf:li>
        </rdf:Alt>
     </dc:description>
  </rdf:Description>
</rdf:RDF>

修改 我感谢约书亚的解释.我发现有趣/奇怪的是,似乎有两种方法可以列出一个值.第一个带有等号,如在tag ="value"中,并包含在rdf:Description括号中(请注意关闭rdf:Description括号):

Edit I appreciate Joshua's explanation. What I find interesting/odd is that there appears to be two different ways to list a value. The first is with an equal sign as in tag="value" and included within the rdf:Description brackets (notice closing rdf:Description bracket):

<rdf:Description rdf:about="" 
   xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmpRights:Marked="True" 
   photoshop:Instructions="Notice closing Bracket here">
</rdf:Description> 

第二个是具有价值

<rdf:Description rdf:about=""
   xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
   <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
</rdf:Description> 

推荐答案

关于RDF

看来,Photoshop所做的工作是读取某些数据的有效,格式正确的RDF/XML序列化,然后在发生的另一种有效,格式良好的RDF/XML序列化中将其显示回UI中.遵守一些其他约定.

About RDF

It appears that what Photoshop is doing is reading a valid, well formed, RDF/XML serialization of some data, and then displaying it back to the user in UI in another valid, well-formed, RDF/XML serialization that happens to follow some additional conventions.

RDF是基于图形的数据表示. RDF中的基本知识是三元组,也称为声明.每个三元组都有一个主语,一个谓语和一个宾语.主语,谓语和宾语都可以是IRI参考.主题和对象也可以是空白节点,对象也可以是文字(例如字符串). RDF/XML是RDF的一种特殊序列化. RDF/XML代码段:

RDF is a graph-based data representation. The fundamental piece of knowledge in RDF is the triple, also called a statement. Each triple has a subject, a predicate, and an object. Subjects, predicates, and objects may all be IRI references; subjects and objects can also be blank nodes, and objects may also be literals (e.g., a string). RDF/XML is one particular serialization of RDF. The RDF/XML snippet:

<rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
  <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
  <photoshop:Headline>OOOHeadline</photoshop:Headline>
  <photoshop:CaptionWriter>OOO </photoshop:CaptionWriter>
</rdf:Description>

包含三个三元组:

<this-document> <http://ns.adobe.com/photoshop/1.0/Instructions> "OOOInstructions"
<this-document> <http://ns.adobe.com/photoshop/1.0/Headline> "OOOHeadline"
<this-document> <http://ns.adobe.com/photoshop/1.0/CaptionWriter> "OOO "

其中,<this-document>是解析引用""的结果(rdf:about属性的值.(XMP文档的第21页说,rdf:about属性的值可能是空字符串……) ,这意味着XMP在物理上是所描述资源的本地应用.应用程序必须依靠文件格式的知识来正确地将XMP与资源相关联."

where <this-document> is the result of resolving the reference "" (the value of the rdf:about attribute. (Page 21 of the XMP documentation says that the value of the rdf:about attribute may be an empty string …, which means that the XMP is physically local to the resource being described. Applications must rely on knowledge of the file format to correctly associate the XMP with the resource".)

<rdf:Description rdf:about=""
    xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/">
  <Iptc4xmpCore:IntellectualGenre/>
</rdf:Description>

<rdf:Description rdf:about=""
    xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
  <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
  <photoshop:Headline>OOOHeadline</photoshop:Headline>
  <photoshop:CaptionWriter>OOO </photoshop:CaptionWriter>
</rdf:Description>

和做的完全一样

<rdf:Description rdf:about=""
    xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
    xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
  <Iptc4xmpCore:IntellectualGenre/>
  <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
  <photoshop:Headline>OOOHeadline</photoshop:Headline>
  <photoshop:CaptionWriter>OOO </photoshop:CaptionWriter>
</rdf:Description>

他们序列化了相同的三元组.无效或不正确.这只是您喜欢的问题.其他变化也是可能的.例如,在某些情况下,您可以使用元素属性来指示属性值.三重:

They serialize the same set of triples. Neither is invalid or incorrect. It's just a matter of which you prefer. Other variations are possible as well. For instance, in some cases you can use element attributes to indicate property values. The triple:

<this-document> <http://ns.adobe.com/photoshop/1.0/Instructions> "OOOInstructions"

可以使用元素来对

进行序列化,如:

can be seralized using elements, as described in Section 2.2 Node Elements and Property Elements of the RDF/XML recommendation:

<rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
  <photoshop:Instructions>OOOInstructions</photoshop:Instructions>
</rdf:Description> 

或使用属性来指示属性值,如同一文档的第2.5节属性属性:

or using attributes to indicate the property value, as described in Section 2.5 Property Attributes of the same document:

<rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
    photoshop:Instructions="OOOInstructions">
</rdf:Description>

关于第二个问题:

当所有输出都很好地混合在一个rdf:Description中时,为什么我应该花时间将输出格式化为RDF规格?

Why should I spend the time to format my output to the RDF specs when it works nicely all jumbled together in a single rdf:Description?

如果输出应为RDF,则应使其成为有效的RDF.它是否采用特殊的美学格式是一个完全不同的问题.在这两者之间进行转换相对容易,我希望Photoshop所做的是按需读取RDF块(即,不依赖于XML序列化的任何特定结构,因为这并不总是相同的(例如,您不应尝试使用XPath操作RDF )),然后以某种方式为用户格式化该数据认为很好,即您提到的约定.

If the output is supposed to be in RDF, you should make it valid RDF. Whether it's in a particular aesthetically pleasing format is an entirely different question. It's relatively easy to translate between the two of these, and I expect that what Photoshop is doing is reading a blob of RDF as it should (i.e., not depending on any particular structure of the XML serialization, since that's not always the same (e.g., you shouldn't try to manipulate RDF with XPath)) and then formatting that data for the user in a way that it considers nice, namely, the convention that you mentioned.

如果还没有,我非常强烈建议您在PHP中使用RDF库来构建元数据图,而不要尝试手动构建RDF/XML序列化.

If you're not already, I very strongly suggest that you use an RDF library in PHP to construct the metadata graph, and not try to construct the RDF/XML serialization by hand.

注意:这是基于文档的更新.根据

Note: this is an update based on the documentation. According to the documentation, page 19, XMP only supports a subset of RDF, so it is still a meaningful question about whether the RDF above and in the question, though suitable as RDF, is suitable as XMP. However, also from page 19:

以下各节描述了XMP数据包中XMP数据的高级结构:

The sections below describe the high-level structure of XMP data in an XMP Packet:

  • 最外面的元素可以是x:xmpmeta元素
  • 它包含一个rdf:RDF元素
  • 其中依次包含一个或多个rdf:Description元素
  • 每个都包含一个或多个XMP属性.
  • The outermost element is optionally an x:xmpmeta element
  • It contains a single rdf:RDF element
  • which in turn contains one or more rdf:Description elements
  • each of which contains one or more XMP Properties.

第20页包含有关rdf:Description元素的详细说明(添加了重点):

Page 20 contains some elaboration about the rdf:Description elements (emphasis added):

rdf:RDF元素可以包含一个或多个rdf:Description元素. …按照惯例,所有 列出了给定架构中的属性,并且仅列出了该架构 在单个rdf:Description元素中. (这不是必需的, 只是一种提高可读性的方法.)

The rdf:RDF element can contain one or more rdf:Description elements. … By convention, all properties from a given schema, and only that schema, are listed within a single rdf:Description element. (This is not a requirement, just a means to improve readability.)

我们需要进一步强调的部分是为了得出结论,我们上面看到的两种形式都是可以接受的.仅仅创建一个大对象可能更容易,并且如果其他工具为您将其拆分为常规形式,您会觉得自己很幸运.

The part with added emphasis is what we need in order to conclude that both forms we've seen above are acceptable. It's probably easier to just create one big blob, and consider yourself lucky if some other tool splits it into the conventional form for you.

这篇关于用jpeg编写XMP元数据(使用PHP)-使用单个或多个rdf:Description块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆