Skip to content

Read and write XMP image metadata in browser and Node.js

License

Notifications You must be signed in to change notification settings

toverainc/xmp-editor

 
 

Repository files navigation

XMP Editor and JavaScript Library

XMP Editor Sreenshot

Online editor and JavaScript library for XMP data in image files. Library mode supports browser and Node.js environments. XMP is a data format to store any set of standardized and custom metadata properties in digital documents and data sets. Currently reading and writing JPG images is supported. PNG and GIF support will be added later. Contributions are always welcome.

Editor

Visit: https://xmp-editor.archilogic.com

Library

WARNING: This is still work in progress. Expect API changes.

Browser example

Open live demo

<!DOCTYPE html>
<html>
  <head>
    <!-- Load lib via CDN -->
    <script src="https://code.archilogic.com/xmp-editor/xmpEditor.umd.min.js"></script>
  </head>
  <body>
    <!-- XMP code will be displayed here -->
    <pre id="xmp-code"></pre>
    <script>
      // Image URL to read XMP from
      var imageUrl =
        "https://storage.3d.io/535e624259ee6b0200000484/2019-06-16_00-16-32_1BCodw/004.jpg";
      // Fetch image as arrayBuffer
      xmpEditor.helpers.urlToArrayBuffer(imageUrl).then(function(arrBuf) {
        // Extract XMP as text. You can use a XML parser to read the nodes.
        var xmpStr = xmpEditor.jpgReadXmp(arrBuf);
        // Show XMP in DOM
        document.getElementById("xmp-code").textContent = xmpStr;
        // Generate new XMP from template
        var xmpStr = xmpEditor.helpers.createNewXmp();
      });
    </script>
  </body>
</html>

Node.js example:

Install:

npm install archilogic-com/xmp-editor#master

Use:

const { jpgReadXmp } = require('archilogic-com/xmp-editor#master')
const pathUtil = require('path')
const { promisify } = require('util')
const { readFile } = require('fs')

async function getXmpString(imgPath) {
  // Read file from disk
  const buf = await promisify(readFile)(imgPath)
  // Convert to array buffer
  const arrBuf = new Uint8Array(buf).buffer
  // Extract XMP string
  return jpgReadXmp(arrBuf)
}

const IMG_PATH = pathUtil.resolve(`image-with-xmp-metadata.jpg`)
getXmpString(IMG_PATH).then(console.log)

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Run your tests

npm run test

Lints and fixes files

npm run lint

Run your unit tests

npm run test:unit

Customize configuration

See Configuration Reference.

About

Read and write XMP image metadata in browser and Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vue 44.1%
  • JavaScript 41.8%
  • CSS 7.6%
  • SCSS 5.0%
  • HTML 1.1%
  • Shell 0.4%