Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

metalsmith-image-resizer

2.0.0 • Public • Published

metalsmith-image-resizer

An image resizing plugin for Metalsmith. Not dependent on imagemagick/graphicsmagick!

Installation

npm install metalsmith-image-resizer --save

Dependencies

metalsmith-image-resizer depends on sharp. If you're on Mac OS X, you'll need to install libvips (brew install homebrew/science/vips). If you're on Linux or Windows, no other dependency should be needed.

Usage

API

var Metalsmith = require('metalsmith');
var imageResizer = require('metalsmith-image-resizer');

Metalsmith(__dirname)
    .source(__dirname + "/src")
    .destination(__dirname + "/build")
    .use(imageResizer({
        glob: "img/backgrounds/*",
        width: 1920,
        height: 1080
    }))
    .build(function(err) {
        if (err) throw err;
    })

You can use imageResizer multiple times to resize different globs of images with different options:

Metalsmith(__dirname)
    .source(__dirname + "/src")
    .destination(__dirname + "/build")
    .use(imageResizer({
        glob: "img/backgrounds/*",
        width: 1920,
        height: 1080
    }))
    .use(imageResizer({
        glob: "img/people/*",
        width: 200,
        height: 200
    }))
    .build(function(err) {
        if (err) throw err;
    })

You can also specify an extension that you'd like to convert your photos to:

var Metalsmith = require('metalsmith');
var imageResizer = require('metalsmith-image-resizer');

Metalsmith(__dirname)
    .source(__dirname + "/src")
    .destination(__dirname + "/build")
    .use(imageResizer({
        glob: "img/backgrounds/*",
        width: 1920,
        height: 1080,
        ext: "jpeg"
    }))
    .build(function(err) {
        if (err) throw err;
    })

Credits

Modeled after @tomterl's metalsmith-convert plugin.

This is my (@kenhoff's) first time maintaining an OSS project! Tips, suggestions, issues, and pull requests are all totally appreciated.

Keywords

none

install

npm i metalsmith-image-resizer

Downloadsweekly downloads

3

version

2.0.0

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability