gpt4 book ai didi

php - 在 jpeg 中写入 XMP 元数据(使用 PHP)- 使用单个或多个 rdf :Description blocks

转载 作者:可可西里 更新时间:2023-11-01 00:46:00 25 4
gpt4 key购买 nike

我正在尝试修改 PHP_JPEG_Metadata_Toolkit 中的代码这样我就可以使用 PHP 为 jpeg 文件正确读取和写入 XMP 数据。目前,由于 XMP block ,jpeg 文件(当由工具包保存时)在 Adob​​e Photoshop & Bridge 中会出错。

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

第二个是在 XMP documentation 之后显示在 Photoshop“文件信息”中的格式整齐的元数据。对于 RDF(声明“按照惯例,来自给定模式的所有属性,并且只有该模式,在单个 rdf:Description 元素中列出。”)

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

两个问题:知道为什么 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 格式精美的 View (已编辑)

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

第二个是值(value)

<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 中的用户遵循一些额外的约定。

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"

可以使用元素序列化,如 Section 2.2 Node Elements and Property Elements 中所述RDF/XML 推荐标准:

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

或使用属性来指示属性值,如 Section 2.5 Property Attributes 中所述同一份文件:

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

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

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 的 blob,因为它应该(即不依赖于 XML 序列化的任何特定结构,因为它并不总是相同的(例如, you shouldn't try to manipulate RDF with XPath )) 然后以用户认为合适的方式为用户格式化该数据,即您提到的约定。

如果您还没有这样做,我非常强烈建议您使用 PHP 中的 RDF 库来构建元数据图,而不是尝试手动构建 RDF/XML 序列化。 p>

关于RDF中的XMP

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

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

  • 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 的详细说明元素(重点添加):

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

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

关于php - 在 jpeg 中写入 XMP 元数据(使用 PHP)- 使用单个或多个 rdf :Description blocks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18668132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com