用jpeg编写XMP元数据(使用PHP) - 使用单个或多个rdf:描述块


Writing XMP Metadata in jpeg (with PHP) - Using Single or Multiple rdf:Description blocks

我正在尝试修改PHP_JPEG_Metadata_Toolkit中的代码,以便我可以使用PHP正确读取和写入jpeg文件的XMP数据。目前,由于XMP块,jpeg文件(由工具包保存时)在Adobe Photoshop和Bridge中出错。

我可以通过两种方式查看Photoshop使用的XMP RDF模式。首先是Photoshop实际上保存在jpg中的内容以及我正在导入的内容。 Photoshop 对所有内容都使用单个 rdf:Description 块。它在块本身中抛出许多架构标识符 (url),并为许多元数据字段添加值。以下是Dublin Core,Photoshop,Iptc4xmpCore等的标签块,但都集中在一个描述标签中。

第二个是Photoshop"文件信息"中显示的格式整齐的元数据,它遵循RDF的XMP文档(其中指出"按照惯例,给定模式中的所有属性,并且只有该架构,都列在单个rdf:Description元素中。

我已经能够按照 Photoshop 实际发送的示例来解决 Photoshop 在由工具包编辑时出现错误的问题(所有内容都在一个 rdf:Description) 下)

两个问题:知道为什么 Photoshop 保存的 XMP 元数据与它在程序中显示的不同吗?和。。。为什么我应该花时间将我的输出格式化为RDF规范,当它在一个rdf:Description中很好地混合在一起时?我是处理所有这些工作的新手,因此任何指导将不胜感激。

这些示例经过编辑,因此您可以更轻松地查看格式差异 - 请原谅两者之间的内容差异,这些差异只是来自编辑。

以下是我从Photoshop收到的(编辑):

<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> 

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

<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 括号):

<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序列化,

然后在UI中以另一个有效的,格式良好的RDF/XML序列化将其显示回用户,该序列化恰好遵循一些其他约定。

RDF是一种基于图的数据表示。 RDF的基本知识是三元组,也称为语句。 每个三元组都有一个主语、一个谓语和一个宾语。 主语、谓语和宾语都可以是 IRI 引用; 主体和宾语也可以是空白节点,宾语也可以是文字(例如,字符串)。 RDF/XML是RDF的一个特殊序列化。 RDF/XML 片段:

<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 与资源相关联"。

行为

<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>

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

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

可以使用元素进行锯齿化,如RDF/XML建议的第2.2节节点元素和属性元素中所述:

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

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

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

那么,关于你的第二个问题:

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

如果输出应该是RDF的,你应该让它成为有效的RDF。 它是否采用特定的美学上令人愉悦的格式是一个完全不同的问题。 在两者之间转换相对容易,我希望Photoshop正在做的是读取RDF的blob(即,不依赖于XML序列化的任何特定结构,因为这并不总是相同的(例如,你不应该尝试用XPath操作RDF)),然后以它认为不错的方式为用户格式化该数据, 即你提到的公约。

如果你还没有,我强烈建议你在PHP中使用RDF库来构造元数据图,而不是尝试手动构造RDF/XML序列化。

关于 RDF 中的 XMP

注意:这是基于文档的更新。根据文档,第19页,XMP只支持RDF的一个子集,所以关于上面和问题中的RDF是否适合作为RDF,是否适合作为XMP仍然是一个有意义的问题。 但是,同样来自第 19 页:

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

  • 最外面的元素是可选的 x:xmpmeta 元素
  • 它包含一个 rdf:RDF 元素
  • 它又包含一个或多个 rdf:Description 元素
  • 每个属性都包含一个或多个 XMP 属性。

第20页包含了一些关于rdf:Description要素的阐述(着重号是后加的):

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

我们需要强调

的部分是我们需要的结论,即我们上面看到的两种形式都是可以接受的。 只创建一个大 blob 可能会更容易,如果其他工具将其拆分为常规形式,则认为自己很幸运。