This is a plugin for Metalsmith that uses node-imagemagick-native to convert image-files
Continuous testing courtesy of travis-ci:
This module is released via npm, install the latest released version with
npm install --save metalsmith-convert
This module uses node-imagemagick-native. You must be able to compile c++ code to install imagemagick-native. The Readme provides instructions for Linux, Mac OS X and Windows respectively.
If using the CLI for Metalsmith, metalsmith-convert can be used like any other plugin by including it in metalsmith.json
. For example:
{
"plugins": {
"metalsmith-convert": {
"src": "**/*.svn",
"target": "png"
}
}
}
For metalsmiths JavaScript API, metalsmith-convert can be used like any other plugin, by attaching it to the function invocation chain on the metalscript object. For example:
var copy = require('metalsmith-convert');
require('metalsmith')(__dirname)
.use(convert({
src: '**/*.svg',
target: 'png'
})
.build();
metalsmith-convert requires a src
and target
options.
src
is a globbing pattern that specifies which files to converttarget
is an imagemagick format specifierextension
the file extension to use for the conversion target (starting with.
). Set to"." + target
if not given explicitly.remove
if set totrue
, don't include the source-file in the build directory.resize
set to{width: XXX, height: YYY}
to resize the image; the name will reflect the size (name_XXX_YYY.ext
) ifnameFormat
is not given.nameFormat
give the format for the names of the converted files, the following placeholders are available%b
the basename of the source file, e.g. givensource.png
, the value will besource
%e
the extension of the target format, including the dot%x
the width of the resulting image%y
the height if the resulting image
It is possible to pass options as array of option-objects to implement multiple rules, e.g. resize to two sizes for different thumbnail sizes:
{
"plugins": {
"metalsmith-convert": [
{
"src": "**/*.svg",
"target": "png",
"resize": {width: 320, height: 240},
"nameFormat": "%b_thumb%e"
},
{
"src": "**/*.svg",
"target": "png",
"resize": {width: 640, height: 480},
"nameFormat": "%b_thumb_large%e"
}
]
}
}