Image Conversion Utility (sharp-image-conversion)
Sharp wrapper for single image resize, manipulation and format conversion then output to file or buffer.
Installation
npm install --save sharp-image-conversion
Usage
const ImageConverter = require('sharp-image-conversion')
const imageConverter = new ImageConverter('./filename.jpg', {
xLimit: 1920,
yLimit: 1080,
})
imageConverter.streamCopy(
'./newFilename.png',
'png',
{
compressionLevel: 5,
quality: 50,
})
imageConverter
.toBuffer('webp')
.then(buffer => {
})
.catch(error => {
console.log(error)
})
API
new Instance(sourceFilePath : String, resizeOption? : Object)
creates an instance and specify the optional resizing parameter object in the format of:
const resizingOptions = {
xLimit: 1920,
yLimit: 1080,
}
Instance.streamCopy(targetFilePath : String, targetFormat? : String, outputOptions? : Object)
copy the file specified during instantiation using node.js stream after converting to the optionally specified image format with optionally appied image manipulation parameters
note 1: refer to Sharp docs for supported image formats.
note 2: specified outputOptions are ignored if targetFormat is undefined or null.
instance.streamCopy('targetPath', undefined, {
option_1: blah_1,
option_2: blah_2,
})
note 3: outputOptions should match the targetFormat according to Sharp docs.
Instance.toBuffer(targetFormat? : String, outputOptions? : Object)
buffer the image data from the file specified during instantiation after converting to the optionally specified image format with optionally appied image manipulation parameters
see notes from Instance.StreamCopy method
License
MIT