An image resizing plugin for Metalsmith. Not dependent on imagemagick/graphicsmagick!
npm install metalsmith-image-resizer --save
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.
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;
})
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.