在jpeg中编写XMP元数据(使用PHP) – 使用单个或多个rdf:描述块
作者:互联网
我试图修改PHP_JPEG_Metadata_Toolkit中的代码,以便我可以使用PHP正确读取和写入jpeg文件的XMP数据.目前,jpeg文件(由Toolkit保存时)会出现Adobe Photoshop&由于XMP块而桥接.
我有两种方法可以看到Photoshop使用的XMP RDF架构.第一个是Photoshop实际上在jpg中保存的内容以及我要导入的内容. Photoshop对所有内容使用单个rdf:Description块.它会在块本身内抛出许多模式标识符(url)PLUS会为许多元数据字段添加值.接下来是Dublin Core,Photoshop,Iptc4xmpCore等的标记块,但所有标记块都集中在一个Description标记中.
第二种是在Photoshop“文件信息”中显示的整齐格式化的元数据,它遵循RD001的XMP documentation(其中指出“按照惯例,来自给定模式的所有属性,只有该模式,列在单个rdf:Description元素中. “)
通过按照Photoshop实际发送的示例(一个rdf下的所有内容:描述),我已经能够通过Toolkit编辑错误来解决问题.
两个问题:任何想法为什么Photoshop保存XMP元数据不同于它在程序中显示的内容?并且……为什么我应该花时间将输出格式化为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#"
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格式很好的视图(已编辑)
<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中:描述括号(注意结束rdf:描述括号):
<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"
可以使用元素进行分类,如RDF / XML建议的Section 2.2 Node Elements and Property Elements中所述:
<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(即不依赖于XML序列化的任何特定结构,因为它并不总是相同的(例如, ,you shouldn’t try to manipulate RDF with XPath))然后以一种它认为不错的方式为用户格式化该数据,即您提到的约定.
如果您还没有,我强烈建议您在PHP中使用RDF库来构建元数据图,而不是尝试手动构建RDF / XML序列化.
关于RDF中的XMP
注意:这是基于文档的更新.根据第19页的the documentation,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,metadata,rdf,xmp 来源: https://codeday.me/bug/20190831/1776557.html