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/react-image-display-control

v1.0.7

Published

Image Display Control React component

Downloads

44

Readme

npm version github actions

 

Image Display Control React Component

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

An easy way to do Image Display Control in your React web app. Made with :heart: by Frameright. Power to the pictures!

Less than 5kB in your final client-side bundle.

  :sparkles: Live demo

  💻 CodeSandbox

Table of Contents

Overview

This React component extends any <img>-like element/component with the ability to retrieve Image Display Control metadata from its image file in order to automatically and responsively zoom in on the most interesting part of the image.

It integrates nicely with other advanced features you may be using in your existing project, e.g.:

It doesn't change the structure of your DOM: your existing CSS rules still apply.

  :sparkles: Live demo

  :bulb: GitHub Discussions

NOTE: if you are not using React, you may want to have a look at the Image Display Control Web component instead.

Without this component

When an image is too big for its <img> HTML element, the best option browsers offer nowadays is to use the object-fit: cover; CSS property in order to scale and middle-crop it:

<img
  src="https://react.frameright.io/assets/pics/skater.jpg"
  width="200"
  height="200"
  style="object-fit: cover;"
/>

This is less than optimal, as there might be, in the example above, a better square-ish region in the image that could be displayed instead of the middle-crop.

Basic usage

This React component extends its <img>-like children with the ability to retrieve image regions from their image metadata, and to zoom in on the best one for the current element size:

<ImageDisplayControl>
  <img
    src="https://react.frameright.io/assets/pics/skater.jpg"
    width="200"
    height="200"
  />
</ImageDisplayControl>

The resulting HTML element is responsive and will automatically reassess the best region to zoom in on when it gets resized, e.g. when the user turns their phone from portrait to landscape.

Youtube

  :sparkles: Live demo

  💻 CodeSandbox

  :bulb: GitHub Discussions

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. This React component uses a library to let the back-end or front-end extract the regions from the image file. It then passes them to the <img> tag and turns it into a web component, which automatically and responsively zooms in on the best region.

Photographers, or anyone else, can use the Frameright webapp to define and store image regions in the metadata of their pictures.

Installation

In your Node.js-based project (e.g. using Next.js or Vite) run:

npm install @frameright/react-image-display-control

Less than 5kB in your final client-side bundle.

  :floppy_disk: Importing in your project

Usage

// src/MyComponent.tsx

import { ImageDisplayControl } from "@frameright/react-image-display-control";

export default function MyComponent() {
  return (
    <ImageDisplayControl>
      <img
        src="https://react.frameright.io/assets/pics/skater.jpg"
        width="200"
        height="200"
      />
    </ImageDisplayControl>
  );
}

This doesn't change the structure of the resulting DOM, i.e.:

  • the <img> tag remains an <img> tag, and
  • no new parent elements are added around it, so
  • the CSS rules that used to target the <img> tag directly will still apply, and
  • the <img> tag will still naturally take the same space and position in the layout.

Other <img>-like elements/components are supported as well, e.g. Next.js <Image>s or React-Bootstrap <Image>s.

  :airplane: Advanced usage

  🌍 Supported environments

  :wrench: Contributing

  📝 Changelog

  :sparkles: Local demo

  :bulb: GitHub Discussions

  :sparkles: Live demo

  🙏 Dependency tree / credits