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

quickthumb-slug

v2.0.2

Published

Fast and secure on-the-fly thumbnail creation middleware for Express

Downloads

7

Readme

QuickThumb-Slug

Fast and secure on-the-fly thumbnail generation middleware for Express, based on QuickThumb. Uses pre-defined sizes to prevent malicious exploitation. Built with Sharp for optimal performance and memory efficiency.

Features

  • On-demand thumbnail generation
  • Pre-defined size configurations for security
  • High-performance image processing with Sharp
  • Support for modern image formats (including WebP)
  • Compatible with Express and Connect
  • Simple slug-based URL format

Installation

npm install quickthumb-slug

Usage

ESM (Recommended)

import express from 'express';
import quickthumb from 'quickthumb-slug';

const app = express();

app.use(quickthumb.static({
    baseDir: new URL('.', import.meta.url).pathname + "/public",
    sizes: {
        square: { width: 400, height: 400, type: "crop" },
        landscape: { width: 1200, height: 600, type: "crop" },
        fitinportrait: { width: 400, height: 700, type: "resize" }
    }
}));

CommonJS (Legacy)

const express = require('express');
const qt = require('quickthumb-slug');

const app = express();

app.use(qt.static({
    baseDir: __dirname + "/public",
    sizes: {
        square: { width: 400, height: 400, type: "crop" },
        landscape: { width: 1200, height: 600, type: "crop" },
        fitinportrait: { width: 400, height: 700, type: "resize" }
    }
}));

Usage in HTML

<!-- Original image -->
<img src="/images/photo.jpg" />

<!-- Thumbnailed version using 'square' configuration -->
<img src="/images/photo-square.jpg" />

Configuration

The static() middleware accepts an options object with the following properties:

| Option | Type | Description | Default | |--------|------|-------------|---------------------| | baseDir | string | Source images directory | Required | | cacheDir | string | Generated thumbnails directory | [baseDir]/thumbs/ | | sizes | object | Size configurations (see below) | Default sizes | | quality | number | JPEG quality (0-100) | 80 |

Size Configuration

Each size configuration in the sizes object can have:

  • width: Width in pixels
  • height: Height in pixels
  • type: Processing type
    • "crop" (default): Exact dimensions using center crop
    • "resize": Maintain aspect ratio, fit within dimensions

Default Sizes

{
    small: { width: 320, height: 9999, type: "crop" },
    medium: { width: 768, height: 9999, type: "crop" },
    large: { width: 1200, height: 9999, type: "crop" }
}

File Naming

Thumbnails are automatically generated based on the filename format: [original-name]-[size-slug].[extension]

Examples:

  • Original: photo.jpg
  • Square thumbnail: photo-square.jpg
  • Landscape version: photo-landscape.jpg

Supported Formats

  • JPEG/JPG
  • PNG
  • GIF
  • WebP

Caching

Generated thumbnails are cached in [cacheDir]/[type]/[slug]/. The cache is automatically invalidated when the source image is modified.

Performance

This library uses Sharp for image processing, which provides:

  • 4-5x faster processing than ImageMagick
  • Lower memory usage
  • Better image quality
  • Native WebP support

Migration from v1.x

If you're upgrading from version 1.x:

  1. No code changes required - API remains compatible
  2. ImageMagick is no longer required
  3. Better memory management and performance
  4. Added WebP support

License

MIT