Skip to main content

JavaScript Library

GitHub repository

Image Display Control metadata parsing library

An easy way to retrieve Image Display Control metadata out of images.

Live demo


This is a wrapper around mattiasw/ExifReader and image-size. Many thanks to mattiasw, netroy, and other contributors!


The Image Display Control web component extends the <img> tag with the ability to accept a list of image regions, and to zoom in on the best one for the current element size, thus achieving better results than object-fit: cover; a.k.a. middle-cropping. Its syntax looks like:

"id": "oneanimal",
"names": ["One animal"],
"shape": "rectangle",
"unit": "relative",
"x": "0.217",
"y": "0.708",
"width": "0.239",
"height": "0.1467"
}, {
"id": "threeanimals",
"names": ["Three animals"],
"shape": "rectangle",
"unit": "relative",
"x": "0.245",
"y": "0.725",
"width": "0.419",
"height": "0.121"

Typically this list of image regions come from the metadata of the image file itself, is retrieved by the back-end, and is placed in the front-end's <img data-image-regions=" attribute.

This is where this library comes into play: it allows your Node.js back-end to easily retrieve this metadata.

  • A React component leveraging this library is available here.
  • A PHP equivalent of this library is available here.


In a Node.js back-end

#!/usr/bin/env node

import { promises as fs } from 'fs';

// npm install @frameright/image-display-control-metadata-parser
import { Parser } from '@frameright/image-display-control-metadata-parser';

// Get it from
const buffer = await fs.readFile('IPTC-PhotometadataRef-Std2021.1.jpg');

const parser = new Parser(buffer);

This has been validated with JPEG, PNG, and WebP images.

📝 Tutorial

📜 Reference

Directly in a browser

For testing purposes, you can use this library directly in the browser:

<body onload="documentLoaded()">

<script type="text/javascript">
async function documentLoaded() {
const image = await fetch(
const arrayBuffer = await image.arrayBuffer();
const buffer = Buffer.Buffer.from(arrayBuffer);
const parser = new ImageDisplayControl.Parser(buffer);
const regions = parser.getIdcMetadata();
console.log(JSON.stringify(regions, null, 2 /*indent*/));

The parsed metadata can then directly be fed to the Image Display Control web component.

This React component is an example of doing that.

Live demo

💻 CodeSandbox

Image Display Control metadata

Nowadays an image file (e.g. JPEG, PNG) can contain this type of image regions in their metadata according to the IPTC standard. Photographers, or anyone else, can use the Frameright webapp to define and store image regions in the metadata of their pictures.