A small node.js library for working with WebP format. Supports the Promise API.
Convert .png image to .webp and save
const converter = require('webpconverter');
const fs = require('fs');
let options = '-q 80';
converter.cwebp('path/to/image.png', options, 'path/to/output.webp')
.then((res) => {
console.log(res) // 'path/to/output.webp'
}).catch((err) => {
throw new Error(err);
});
Convert .png image to .webp without saving
const converter = require('webpconverter');
const fs = require('fs');
let options = '-q 80';
converter.cwebp('path/to/image.png', options)
.then((res) => {
// Do something with data
fs.writeFile(path.join(__dirname, 'path/to/output.webp'), res, 'hex');
}).catch((err) => {
throw new Error(err);
});
Convert .webp image to .png format without saving
const converter = require('webpconverter');
const fs = require('fs');
return converter.dwebp('path/to/image.webp')
.then((res) => {
// Do something with data
fse.writeFile(path.join(__dirname, 'path/to/output.png'), res, 'hex');
}).catch((err) => {
throw new Error(err);
});
- cwebp - image to webp.
- dwebp - webp to image.
- gif2webp - gif animated image to animated WebP.
- webpmux - work in progress! Not supproted yet. Create animated WebP files from non-animated WebP images, extract frames from animated WebP images, and manage XMP/EXIF metadata and ICC profile.
libwebp 0.6.1 (2017, November)