webp-converter v2.3.3
A small node.js library for converting any image to webp file format or converting webp image to any image file format.
This library uses precompiled executables of WebP(v1.1.0) for more info visit WebP
For converting other image formats to webp, please read this documentation cwebp Encoder
For converting webp image to other image format, please read this documentation dwebp Encoder
For converting gif image to webp, please read this documentation gif2webp Converter
For creating animated webp image using webp images, please read this documentation webpmux Muxer
What's New
How to use
Fix Permission Issue
const webp=require('webp-converter');
webp.grant_permission();
cwebp
Convert other image format to webp
const webp=require('webp-converter');
const result = webp.cwebp("nodejs_logo.jpg","nodejs_logo.webp","-q 80",logging="-v");
result.then((response) => {
console.log(response);
});
Convert base64 image to webpbase64 image
const webp=require('webp-converter');
function get_webpbase64(path) {
fs.readFile(path, function (error, data) {
if (error) {
throw error;
} else {
let buf = Buffer.from(data);
let dataBase64 = Buffer.from(buf).toString('base64');
let result = webp.str2webpstr(dataBase64,"jpg","-q 80");
result.then(function(result) {
console.log(result)
});
}
});
}
get_webpbase64("./nodejs_logo.jpg")
get_webpbase64("./nodejs_logo.jpg","/home/user/Desktop/webp/temp")
Convert buffer to webp buffer
const webp=require('webp-converter');
function get_webpbuffer(path) {
fs.readFile(path, function (error, data) {
if (error) {
throw error;
} else {
let result = webp.buffer2webpbuffer(data,"jpg","-q 80");
result.then(function(result) {
console.log(result)
});
}
});
}
get_webpbuffer("./nodejs_logo.jpg")
get_webpbuffer("./nodejs_logo.jpg","/home/user/Desktop/webp/temp")
dwebp
Convert webp image to other image format
const webp=require('webp-converter');
const result = webp.dwebp("nodejs_logo.webp","nodejs_logo.jpg","-o",logging="-v");
result.then((response) => {
console.log(response);
});
gif2webp
Convert gif image to webp
const webp=require('webp-converter');
const result = webp.gwebp("linux_logo.gif","linux_logo.webp","-q 80",logging="-v");
result.then((response) => {
console.log(response);
});
webpmux
Add ICC profile,XMP metadata and EXIF metadata
const webp=require('webp-converter');
const result = webp.webpmux_add("in.webp","icc_container.webp","image_profile.icc","icc",logging="-v");
result.then((response) => {
console.log(response);
});
Extract ICC profile,XMP metadata and EXIF metadata
const webp=require('webp-converter');
const result = webp.webpmux_extract("anim_container.webp","image_profile.icc","icc",logging="-v");
result.then((response) => {
console.log(response);
});
Strip ICC profile,XMP metadata and EXIF metadata
const webp=require('webp-converter');
const result = webp.webpmux_strip("icc_container.webp","without_icc.webp","icc",logging="-v");
result.then((response) => {
console.log(response);
});
Create an animated WebP file from Webp images
const webp=require('webp-converter');
let input=[{"path":"./frames/tmp-0.webp","offset":"+100"},{"path":"./frames/tmp-1.webp", "offset":"+100"},{"path":"./frames/tmp-2.webp","offset":"+100"}];
const result = webp.webpmux_animate(input,"anim_container.webp","10","255,255,255,255",logging="-v");
result.then((response) => {
console.log(response);
});
Get a frame from an animated WebP file
const webp=require('webp-converter');
const result = webp.webpmux_getframe("anim_container.webp","frame_2.webp","2",logging="-v");
result.then((response) => {
console.log(response);
});
Installation
$ npm install webp-converter
License
MIT