npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@frameright/image-display-control-metadata-parser

v2.0.0

Published

Image Display Control metadata parsing library

Downloads

151

Readme

npm version github actions

 

Image Display Control metadata parsing library

➡️ See this document rendered at docs.frameright.io/javascript

An easy way to retrieve Image Display Control metadata out of images. Made with :heart: by Frameright. Power to the pictures!

  :sparkles: Live demo

  :bulb: GitHub Discussions

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

Table of Contents

Overview

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:

<img
  is="image-display-control"
  src="https://images.pexels.com/photos/3625715/pexels-photo-3625715.jpeg"
  width="200"
  height="200"
  data-image-regions='[{
    "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.

NOTES:

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

Usage

In a Node.js back-end

#!/usr/bin/env node
// ./myscript.mjs

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 https://iptc.org/std/photometadata/examples/IPTC-PhotometadataRef-Std2021.1.jpg
const buffer = await fs.readFile('IPTC-PhotometadataRef-Std2021.1.jpg');

const parser = new Parser(buffer);
console.log(parser.getIdcMetadata());

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

  :memo: Tutorial

  :scroll: Reference

  :wrench: Contributing

  📝 Changelog

  :bulb: GitHub Discussions

Directly in a browser

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

<html>
  <body onload="documentLoaded()">
    <script
      type="module"
      src="https://cdn.jsdelivr.net/npm/@frameright/[email protected]/dist/image-display-control-metadata-parser-standalone.min.js"
    ></script>

    <script type="text/javascript">
      async function documentLoaded() {
        const image = await fetch(
          'https://iptc.org/std/photometadata/examples/IPTC-PhotometadataRef-Std2021.1.jpg'
        );
        const buffer = await image.arrayBuffer();
        const parser = new ImageDisplayControl.Parser(buffer);
        const regions = parser.getIdcMetadata();
        console.log(JSON.stringify(regions, null, 2 /*indent*/));
      }
    </script>
  </body>
</html>

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

This React component is an example of doing that.

  :sparkles: 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.