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

@poly67/react

v0.1.0

Published

React bindings for react-image-optimizer: an <ImageOptimizer> dropzone component and useImageOptimizer hook that shrink uploads to fit strict size/dimension requirements, entirely in the browser.

Downloads

89

Readme

@poly67/react

React bindings for @poly67/core: a drag-and-drop <ImageOptimizer> component and a useImageOptimizer hook that shrink uploaded images to fit strict size/dimension requirements — entirely in the browser, no server round-trip.

See the root README for the full guide and the algorithm explanation.

Install

npm install @poly67/react

react and react-dom (18 or 19) are peer dependencies.

<ImageOptimizer />

import { ImageOptimizer } from "@poly67/react";

function ProfilePhotoUpload() {
  return (
    <ImageOptimizer
      maxSizeKB={20}
      maxWidth={200}
      maxHeight={200}
      format="jpeg"
      quality={0.9}
      autoOptimize
      preview
      onProgress={(p) => console.log(p.stage, p.progress)}
      onSuccess={(result) => {
        const formData = new FormData();
        formData.append("photo", result.file);
        fetch("/api/upload", { method: "POST", body: formData });
      }}
      onError={(error) => console.error(error)}
    />
  );
}

Ships with a minimal, accessible default UI (dropzone + native file input + preview + status text), which you can fully replace with a render-prop:

<ImageOptimizer maxSizeKB={20} maxWidth={200} maxHeight={200}>
  {({ isDragActive, isOptimizing, previewUrl, result, error, openFileDialog }) => (
    <div className={isDragActive ? "dropzone--active" : "dropzone"}>
      {previewUrl && <img src={previewUrl} alt="" />}
      <button type="button" onClick={openFileDialog} disabled={isOptimizing}>
        {isOptimizing ? "Optimizing…" : "Choose photo"}
      </button>
      {result && <p>{result.sizeKB.toFixed(1)}KB, ready to upload</p>}
      {error && <p role="alert">Couldn't process that image.</p>}
    </div>
  )}
</ImageOptimizer>

Props

All OptimizeOptions fields (maxSizeKB, maxWidth, maxHeight, format, quality, minQuality, background, preserveAspectRatio, fit, crop, correctOrientation) are accepted directly, plus:

| Prop | Type | Default | Description | | --- | --- | --- | --- | | autoOptimize | boolean | true | Optimize as soon as a file is selected/dropped. | | preview | boolean | true | Show an object-URL preview of the selected file. | | multiple | boolean | false | Allow selecting more than one file. | | accept | string | "image/*" | Forwarded to the file input. | | disabled | boolean | false | Disable interaction. | | className / style | — | — | Applied to the root element. | | children | ReactNode \| (state) => ReactNode | — | Custom UI / render prop. | | onProgress | (p: OptimizeProgress) => void | — | Pipeline progress updates. | | onSuccess | (r: OptimizeResult) => void | — | Called once optimization finishes. | | onError | (e: unknown) => void | — | Called if optimization throws. |

Ref API

When autoOptimize is false, trigger optimization imperatively:

const ref = useRef<ImageOptimizerHandle>(null);

<ImageOptimizer ref={ref} autoOptimize={false} maxSizeKB={20} />
<button onClick={() => ref.current?.optimize()}>Optimize</button>

ImageOptimizerHandle: { optimize(), reset(), openFileDialog() }.

useImageOptimizer(options?)

For fully custom UIs:

import { useImageOptimizer } from "@poly67/react";

function Uploader() {
  const { optimize, isOptimizing, progress, result, error } = useImageOptimizer({
    maxSizeKB: 20,
    maxWidth: 200,
    maxHeight: 200,
  });

  return (
    <input
      type="file"
      accept="image/*"
      onChange={(e) => e.target.files?.[0] && optimize(e.target.files[0])}
    />
  );
}

Returns { optimize, isOptimizing, progress, result, error, reset, abort }. Calling optimize() again automatically aborts a still-running previous call.

Direct core usage

optimizeImage is re-exported for one-off calls that don't need component state:

import { optimizeImage } from "@poly67/react";

const { file } = await optimizeImage(rawFile, { maxSizeKB: 20 });

License

MIT