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

metalsmith-img-sharp

v0.0.6

Published

A Metalsmith plugin to process images with Sharp.

Downloads

133

Readme

metalsmith-img-sharp

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

A Metalsmith plugin to process images with Sharp.

This plugin is designed to be a modernized, grossly more performant, drop-in replacement for the outdated and unmaintained metalsmith-sharp plugin.

Installation

npm install --save metalsmith-img-sharp

JavaScript Usage

With one object of options:

import Metalsmith from 'metalsmith';
import sharp from 'metalsmith-img-sharp';

Metalsmith(__dirname)
    .use(sharp({
        src: '**/*.@(bmp|png)',
        namingPattern: '{dir}{name}.jpg',
        methods: [
          {
            name: 'resize',
            args: [200, 200]
          },
          {
            name: 'jpeg',
            args: { quality: 85 }
          }
        ],
        moveFile: true
        // other options here
    }))
    .build((err) => {
        if (err) {
            throw err;
        }
    });

or with an array of options:

import Metalsmith from 'metalsmith';
import sharp from 'metalsmith-img-sharp';

Metalsmith(__dirname)
    .use(sharp([
      {
        src: '**/*.jpg',
        methods: [{
          name: 'resize',
          args: [200, 200]
        }]
        // other options here
      },
      {
        src: '**/*.@(bmp|png)',
        namingPattern: '{dir}{name}.jpg',
        methods: [{
          name: 'jpeg',
          args: { quality: 85 }
        }],
        moveFile: true
        // other options here
      }
    ]))
    .build((err) => {
        if (err) {
            throw err;
        }
    });

Options

methods (required)

Type: { name: string, args: unknown}[]

An array of Sharp methods to apply to each file. See the full Sharp documentation on what resizing, compositing, color manipulation, and other functions are available.

args can be one of:

  • A single value if the Sharp function only takes one argument
    • This can be an object if the Sharp function takes an object
  • An array of values if the Sharp function takes multiple arguments
  • A method that takes a Sharp metadata object and returns an array of values

Example:

sharp({
  src: '**/*.@(bmp|png)',
  methods: [
    {
      // Halve the size of the image
      name: 'resize',
      args: (metadata) => [
        Math.round(metadata.width / 2),
        Math.round(metadata.height / 2),
      ]
    },
    {
      // Flatten a transparent image with a solid background color
      name: 'flatten',
      args: { background: '#ffffff' }
    }
  ]
})

pattern (optional)

Type: string Default: **/*.@(avif|bmp|gif|heic|jpg|jpeg|png|svg|webp)

A micromatch glob pattern for image files to process.

namingPattern (optional)

Type: string Default: {dir}{base}

The output filename for every processed image. Placeholders available:

  • {dir}: Directory of file followed by slash
  • {base}: Full filename with extension
  • {name}: Filename without extension
  • {ext}: File extension with leading dot

moveFile (optional)

Type: boolean Default: false

If a new file was created because namingPattern, should the old file be deleted.

sharp (optional)

Type: object Default: {}

Options to pass to the Sharp constructor.

parallelism (optional)

Type: number Default: the number of logical CPU cores available

The maximum number of image files to process concurrently.

Changelog

Changelog