I wanted a program to inject Extensible Metadata Platform (XMP) sidecar (stand-alone) files into an image file. Image metadata is mostuseful when embedded into image filesafter all. I was surprised to learn that options for XMP editors were thin on the ground. I had to create a new program to get the job done.
Two existing programs come to mind:Exiv2和ExifTool. Both tools interpret the sidecar file and write the recognize metadata back into the image files using their own distinct set of rules. This would be fine except when you want to include metadata from namespaces/vocabularies they don’t recognize or want to make sure the resulting metadata takes up as little space as possible.
Exiv2writes XMP in a compacted form that isn’t compatible with the underlyingRDFstandard, the XMP standard, and isn’t supported by any popular image viewers or operating systems. ExifTool, on the other hand, produces overly verbose XMP markup that takes up more space than necessary. It can be configured to compact it somewhat and reduce optional whitespace. At my request, the author of ExifTool added even more options for compacting it further.
Both of these tools also have a few different image format-specific bugs and they don’t support all of the formats I need (including WebP and SVG).
I wanted a program that takes an XMP sidecar file without processing it and injects it as-is into the right place inside of image files. A third program called
webpmuxdoes exactly this. However, it only works for WebP images.
So I wrote a new program called
embed_xmpto fulfill this need. It’s available as a Ruby gem/library and as a command-line interface (CLI). (Sorry if you were expecting a graphical user interface!) It supports writing XMP sidecars into JPEG, PNG, SVG, and WebP image files.
It’s not quite what I explained above, though. It doesn’t inject XMP data verbatim. It will wrap the XMP data in an
xpacketXML processing instruction, as recommended by theXMP规格. This ensures the broadest client-compatibility. It also doesn’t preserve XML whitespace (unless overwritten by an
xml:space在XMP文件中的指令）。空格可以大量文件的大小超过它在其他情况下，因为当嵌入到文件XMP数据不被压缩。图片文件usually not recompressedwhen served through a web server either.
该计划将不会进行其他更改图像文件，除非在必要时通过图像格式。最显着的变化是基本的WebP图像被升级为需要时WebP的扩展文件格式（WEFF）。WEFF可能无法在旧版浏览器渲染。该WebP container specificationonly supports embedding XMP data into WEFF files.
You’ll need another program to author the XMP sidecar files — such as Corel AfterShot Pro, Adobe Photoshop or Lightroom, or Photo Mechanic — and can then use
embed_xmpto insert that sidecar into an image file. You’ll probably want to use
embed_xmpwith some sort of content management system that holds image metadata, though.
You can install the
embed_xmpCLI and library usingRubyGems. You’ll need to install Ruby and RubyGems first, and then run the following command to download and install the latest version of
该CLI tool requires three positional arguments:
xpacketXML processing instruction. There are no sanity-checks or format-validation.
该Ruby library has a few more options. The short and sweet usage instructions are as follows:
You can find some more detailed usage in thedocumentation on RubyDoc. (You also installed a local copy of the documentation along with the gem.) Although not the intended use, it also includes methods for removing XMP data from image files.
该XMP规格requires that you ensure that legacy/other metadata formats — e.g. native metadata fields — are updated to be aligned with the XMP metadata.
I’ve not yet published the source code for this gem anywhere. However, you get a copy when installing the gem via RubyGems. It’s licensed under a BSD 3-Clause license. I’m evaluatingdistributed alternatives to GitHub并没有想上传任何更多的仓库那里。一旦我决定上的东西我会更新这篇文章链接到源代码。