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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mts-pjsc/image-optimize

v1.3.15

Published

React component for image optimizer

Readme

@mts-pjsc/image-optimize

npm version License: Apache-2.0 Contributor Covenant

A React component for automatic image optimization. Works in conjunction with the Image Optimizer microservice.

Overview

This library provides a drop-in replacement for the standard <img> element that automatically optimizes images based on the user's device, screen size, and browser capabilities. The component communicates with a backend optimization service to deliver the most efficient image format and size.

Features

  • Responsive resizing — automatically selects optimal image dimensions based on container size and device pixel ratio
  • Modern format support — converts images to WebP or AVIF when supported by the browser
  • Quality control — configurable compression quality for fine-tuned optimization
  • Lazy evaluation — determines optimal size after component mount for accurate container measurement
  • Resize handling — recalculates optimal image size on window resize with debouncing
  • Next.js compatible — includes "use client" directive for React Server Components support
  • Zero configuration — works out of the box with sensible defaults

Prerequisites

The Image Optimizer microservice must be deployed and accessible at the /optimizer path on your server.

Installation

npm install @mts-pjsc/image-optimize

Requirements

  • React 16.0.0 or higher

Basic Usage

Replace standard <img> elements with the Image component:

import { Image } from "@mts-pjsc/image-optimize";

function App() {
    return (
        <Image
            src="/images/hero-banner.png"
            alt="Hero banner"
        />
    );
}

API Reference

Image Component

The Image component accepts all standard <img> attributes plus the following:

| Prop | Type | Default | Description | |------|------|---------|-------------| | src | string | — | Required. Image source URL | | alt | string | — | Required. Alternative text for accessibility | | offset | number | 0 | Adjust the selected size breakpoint (-1 for smaller, +1 for larger) | | quality | number | — | Compression quality (0-100). Uses server default if not specified | | setRef | (elem: HTMLImageElement \| null) => void | — | Callback to receive the underlying img element reference |

Static Configuration

Configure global behavior through static properties:

import { Image } from "@mts-pjsc/image-optimize";

// Skip optimization and use original URLs (useful for local development)
Image.isUseSourceUrl = process.env.NODE_ENV !== "production";

// Override image origin for CORS or microfrontend scenarios
Image.imgOrigin = "https://cdn.example.com";

// Custom breakpoints for responsive sizing (default: [160, 320, 640, 1280, 1920])
Image.controlPoints = [320, 640, 1024, 1440, 2560];

// Enable diagnostic logging in development
Image.isShowDiagnostic = true;

Examples

With Quality Control

<Image
    src="/images/photo.jpg"
    alt="High quality photo"
    quality={85}
/>

With Size Offset

// Request a larger size than calculated (useful for hero images)
<Image
    src="/images/banner.png"
    alt="Banner"
    offset={1}
/>

With Ref Callback

<Image
    src="/images/chart.png"
    alt="Chart"
    setRef={(elem) => {
        if (elem) {
            elem.decode().then(() => console.log("Image decoded"));
        }
    }}
/>

Development Configuration

// In your app initialization
import { Image } from "@mts-pjsc/image-optimize";

if (process.env.NODE_ENV !== "production") {
    Image.isUseSourceUrl = true;
    Image.isShowDiagnostic = true;
}

How It Works

  1. The component mounts and measures the container width
  2. Based on container size and device pixel ratio, it selects an optimal size from the control points
  3. Browser capabilities are detected (AVIF > WebP > original format)
  4. A request URL is constructed: /optimizer/optimize?src=...&size=...&format=...
  5. The optimized image is loaded and displayed
  6. On window resize, the process repeats with debouncing to prevent excessive requests

Helper Functions

The library also exports utility functions for format detection:

import { checkWebpFeature, checkAvifFeature } from "@mts-pjsc/image-optimize";

const supportsWebP = await checkWebpFeature();
const supportsAvif = await checkAvifFeature();

License

Apache-2.0

Contributing

See CONTRIBUTING.md for development guidelines.

Related Projects