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

@pixengine/core

v0.3.0

Published

Policy-based image optimization engine for modern web applications

Readme

@pixengine/core

English | 한국어

Policy-based image optimization engine for modern web applications.

Installation

npm install @pixengine/core
# or
pnpm add @pixengine/core
# or
yarn add @pixengine/core

Quick Start

import { optimize } from "@pixengine/core";
import { SharpEngine } from "@pixengine/adapter-engine-sharp";
import { LocalStorage } from "@pixengine/adapter-storage-local";

const manifest = await optimize({
  input: {
    filename: "photo.jpg",
    bytes: imageBuffer,
    contentType: "image/jpeg",
  },
  policy: (ctx) => ({
    variants: [
      { width: 400, format: "webp", quality: 80 },
      { width: 800, format: "webp", quality: 85 },
    ],
  }),
  engine: new SharpEngine(),
  storage: new LocalStorage({
    baseDir: "./uploads",
    baseUrl: "https://example.com/uploads",
  }),
});

console.log(manifest);
// {
//   original: { width: 1920, height: 1080, format: 'jpeg', bytes: 524288 },
//   variants: [
//     { key: 'variants/photo_400w.webp', url: '...', width: 400, ... },
//     { key: 'variants/photo_800w.webp', url: '...', width: 800, ... }
//   ]
// }

Features

  • 🎯 Policy-First Architecture: Define optimization strategies as executable functions
  • 🔌 Pluggable Adapters: Swap engines and storage backends without code changes
  • 📦 Automatic Variant Management: Generate multiple formats and sizes from single source
  • 📊 Rich Metadata: Full image metadata (color space, alpha, density, EXIF) available in policy context
  • 🖼️ HTML Markup Generation: Convert manifests to responsive <picture> elements
  • 🚀 TypeScript Native: Full type safety and IntelliSense support

Core Concepts

Policy

A policy is a function that determines what image variants to generate. It receives a context object containing image metadata:

import { Policy } from "@pixengine/core";

const responsivePolicy: Policy = (ctx) => {
  // ctx contains:
  // - width, height, bytes, format: Basic image info
  // - filename, contentType: File info
  // - metadata: Rich metadata (hasAlpha, space, density, exif, etc.)

  const variants = [];

  if (ctx.width > 1200) {
    variants.push({ width: 1200, format: "webp", quality: 85 });
  }
  if (ctx.width > 800) {
    variants.push({ width: 800, format: "webp", quality: 80 });
  }
  variants.push({ width: 400, format: "webp", quality: 75 });

  return { variants };
};

TransformEngine

Interface for image processing engines:

interface TransformEngine {
  probe(input: PixEngineInput): Promise<{
    width: number;
    height: number;
    format: string;
    // ...other metadata
  }>;

  transform(args: {
    input: PixEngineInput;
    width?: number;
    height?: number;
    format?: "webp" | "avif" | "jpeg" | "png";
    quality?: number;
  }): Promise<{
    bytes: Uint8Array;
    width: number;
    height: number;
    format: string;
  }>;
}

StorageAdapter

Interface for storage backends:

interface StorageAdapter {
  put(args: {
    key: string;
    bytes: Uint8Array;
    contentType: string;
    meta: { width: number; height: number; format: string };
  }): Promise<{ url: string }>;
}

API Reference

optimize(options)

Main orchestration function.

Parameters:

  • input: PixEngineInput - Source image data
    • filename: string - Original filename
    • bytes: Uint8Array - Image data
    • contentType: string - MIME type
  • policy: Policy - Optimization strategy function
  • engine: TransformEngine - Image processing engine
  • storage: StorageAdapter - Storage backend

Returns: Promise<Manifest>

  • original - Original image metadata
  • variants - Array of generated variants with URLs

generatePicture(manifest, options)

Converts a Manifest into a responsive <picture> HTML string.

Parameters:

  • manifest: Manifest - Result from optimize()
  • options: PictureOptions
    • alt: string - Alt text (required)
    • sizes?: string - Responsive sizes attribute
    • className?: string - CSS class name
    • loading?: "lazy" | "eager"
    • decoding?: "async" | "sync" | "auto"
    • fallbackFormat?: string

Returns: string (HTML)

Ecosystem

Adapters

Middleware

  • @pixengine/middleware-express - Express.js middleware
  • @pixengine/middleware-nextjs - Next.js App Router handler
  • @pixengine/middleware-jit - On-demand (JIT) image transformation

Examples

See the examples directory for complete working examples.

License

MIT © PixEngine Team

Links