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

@node-media-library/optimizers

v1.0.0

Published

Binary image optimizers (jpegoptim, pngquant) for node-media-library

Readme

@node-media-library/optimizers

Binary image optimizers for node-media-library: jpegoptim for JPEGs and pngquant for PNGs, both implementing core's ImageOptimizer interface.

System Requirements

Requires the jpegoptim and/or pngquant binaries:

  • macOS: brew install jpegoptim pngquant
  • Linux (Debian/Ubuntu): apt install jpegoptim pngquant
  • Linux (Fedora/RHEL): dnf install jpegoptim pngquant

Usage

Add the optimizers to your optimizers array:

import { createMediaLibrary } from '@node-media-library/core'
import { jpegoptimOptimizer, pngquantOptimizer } from '@node-media-library/optimizers'

createMediaLibrary({
  // ...
  optimizers: [jpegoptimOptimizer(), pngquantOptimizer()],
})

Each optimizer inspects OptimizeContext.format and returns null (pass — the un-optimized buffer is kept) for formats it doesn't handle, or when its binary is missing from PATH/the configured path.

ctx.format is only populated for conversions with an explicit .format('jpeg')/.format('png') (plus PDF/video rasterizations, which resolve to png) — it's null for conversions left at the keep-original-format default and for responsive variants generated from the original file, so those pass through both optimizers unoptimized.

Acceptance rule

Core only ever accepts an optimizer's output when it is strictly smaller than the buffer it was given — larger-or-equal results are discarded and the original buffer is kept, and an optimizer that throws is warned (console.warn) and skipped rather than failing the conversion/responsive write. This applies uniformly whether the buffer came from jpegoptimOptimizer/pngquantOptimizer or a custom ImageOptimizer. Originals and LQIP placeholders are never passed through an optimizer.

Configuration

jpegoptimOptimizer(options?)

  • jpegoptimPath (string): Path to the jpegoptim binary. Default: 'jpegoptim' (assumes it's on PATH)
  • max (number): Quality cap 0-100. Default: 85

pngquantOptimizer(options?)

  • pngquantPath (string): Path to the pngquant binary. Default: 'pngquant' (assumes it's on PATH)
  • quality (string): Quality range, e.g. '65-90'. Default: undefined (pngquant's own default)

Example

jpegoptimOptimizer({ jpegoptimPath: '/usr/local/bin/jpegoptim', max: 80 })
pngquantOptimizer({ pngquantPath: '/usr/local/bin/pngquant', quality: '65-90' })

Testing

Tests include binary-gated suites that skip when jpegoptim/pngquant are not available. Pure tests (arg builders, unsupported-format handling) always run:

pnpm --filter @node-media-library/optimizers test
  • ✓ Pure tests (arg builders, format/missing-binary handling) run without either binary
  • ⊘ Binary-gated tests skip if jpegoptim/pngquant not found
  • Install jpegoptim and pngquant to run all tests