prims
v0.2.0
Published
Batch processing images. A simple way to generate responsive images.
Downloads
26
Maintainers
Readme
Prims
A program built on top of sharp to batch processing images from an input directory. A simple way to generate responsive images.
- Process multiple images.
- Convert to
jpeg
,png
,webp
,tiff
. - Resize to a list of specified widths and heights.
- Fit image (cover, contain, fill, inside, outside).
- Preserve or remove image metadata.
- Customize naming convention.
- Optional interactive CLI.
- Lightweight (sharp is the only dependency).
- Runs in nodejs v8 and up.
Install
npm install --save-dev prims
You can also install the optional prims-cli.
Quick Start
const prims = require('prims');
prims({
input: path.resolve(__dirname, './images'),
convert: {
jpeg: {
quality: 70
},
webp: {
quality: 60
}
},
resize: {
widths: [ 400, 800 ]
}
});
- Read files inside
images
folder. - Convert images to
jpeg
at 70% quality and towebp
at 60% quality. - Each converted images will also be resized to the selected
resize.widths
. - Because
resize.heights
is omitted, height for each image is calculated automatically to preserve aspect ratio. - Output all processed images to
./images/processed-images/
.
Output:
[name]_400w.jpeg
[name]_400w.webp
[name]_800w.jpeg
[name]_800w.webp
Examples
Go to examples page.
API
Go to api page.
Test locally
yarn run test
See tests folder.
Contribution
Contributions are welcome.