Node.js Project to Convert Animated GIF Image to Webp Image Using gif2webp Library Full Project For Beginners

Node.js Project to Convert Animated GIF Image to Webp Image Using gif2webp Library Full Project For Beginners

 

Welcome folks today in this post we will be converting animated gif image to webp image using gif2webplibrary. All the full source code of the application is given below.

 

 

 

Get Started

 

 

 

 

In order to get started we need to install the gif2webp library by using the npm command

 

 

npm i gif2webp

 

After installing this library we need to create an index.js file and copy paste the following code

 

 

var gif2webp = require ("gif2webp");
var fs = require ("fs");

var buffer = fs.readFileSync ("some.gif");
var options = {
    source: buffer,
    lossy: true
};

gif2webp.convert (options, function (error, buffer) {
  // do something with the WebP buffer.
};

 

 

Now in this block of code as you can see we are taking the input.gif file and converting to webp image. And we are using this method gif2webp.convert to convert gif to webp and we are passing the options and then in the second argument we are having the callback function which contains the webp image.

See also  Build a ASCII Text to Binary Codes Converter (And Vice Versa) Web App in HTML5 CSS3 and Javascript Full Project For Beginners

 

This library supports different options

 

convert (options, callback)

The first argument is an options object. The only required option is source, this should be a Buffer containing the gif data; all others are optional.

  • source – The gif Buffer.
  • lossy – Encode image using lossy compression Boolean.
  • mixed – For each frame in the image, pick lossy or lossless compression heuristically Boolean.
  • quality – Quality factor (0:small..100:big).
  • method – Compression method Quality (0=fast, 6=slowest).
  • kmin – Min distance between key frames.
  • kmax – Max distance between key frames.
  • filter – Filter strength (0=off..100).
  • metadata – Comma separated list of metadata to copy from the input to the output if present. Valid values: all, none, icc, xmp (default) String.
  • mt – Use multi-threading if available Boolean.
  • verbose – Verbose output Boolean.

 

 

 

Leave a Reply