webp-conv is a Node.js module for converting both animated and static WebP files to GIF or PNG format. This tool leverages the powerful libwebp library to provide high-quality conversions. With this tool, you can easily convert your WebP images using flexible job-based configuration, making it a convenient solution for your image conversion needs.
DEPRECATION WARNING: The
convert()method is deprecated and will be removed in a future major version. Please migrate to the newconvertJobs()method which offers better functionality, error handling, and job-based processing capabilities.
You can install webp-conv using npm:
npm install @caed0/webp-convβ RECOMMENDED: Use the job-based approach with
convertJobs()for the best experience and functionality.
The job-based approach allows you to process multiple conversions with individual settings:
const webpconv = require('@caed0/webp-conv');
const converter = new webpconv({ quality: 80, transparent: '0x000000' }); // Default settings
// Single job
const singleJob = {
input: 'input.webp',
output: 'output.gif', // Optional - auto-generated if not provided
settings: { quality: 100, transparent: '0xFFFFFF' } // Optional - overrides defaults
};
const result = await converter.convertJobs(singleJob);
// Multiple jobs
const jobs = [
{
input: 'animated.webp',
output: 'animated.gif',
settings: { quality: 90 }
},
{
input: 'static.webp',
// output auto-generated as 'static.png'
settings: { quality: 95 }
},
{
input: 'transparent.webp',
output: 'transparent.gif',
settings: { quality: 85, transparent: '0x00FF00' }
}
];
const results = await converter.convertJobs(jobs);
β οΈ DEPRECATED: Theconvert()method is deprecated and will be removed in a future version. Please use the job-basedconvertJobs()method instead for better functionality and more flexible processing.
The original method is still supported for backward compatibility:
const webpconv = require('@caed0/webp-conv');
const converter = new webpconv();
const input = 'input.webp';
const output = 'output.gif';
await converter.convert(input, output, { quality: 10, transparent: '0x000000' });Each job object can have the following properties:
input(required): The path to the input WebP file you want to convert.output(optional): The path where the converted file will be saved. If not provided, it will be auto-generated based on the input filename and detected format (animated WebP β .gif, static WebP β .png).settings(optional): An object containing conversion options that override the converter's default settings for this specific job.
You can set default options when creating a converter instance:
const converter = new webpconv({
quality: 85,
transparent: '0xFFFFFF'
});These defaults will be used for all conversions unless overridden by individual job settings.
The convertJobs method takes the following parameter:
jobs: A single job object or an array of job objects
β οΈ DEPRECATED: This method is deprecated. UseconvertJobs()instead.
The convert method takes the following parameters:
input: The path to the input WebP file you want to convert.output: The path where the converted file will be saved.options(optional): An object containing additional options for the conversion (only apply if the output is an gif).
Both methods support the following settings (only apply to GIF output):
quality: The quality of the output image (0-100). Higher values result in better quality, but larger file sizes. (Default: 10)transparent: A string specifying the transparency color in hexadecimal format (e.g., '0xRRGGBB' or '0xRRGGBBAA'). This option is only applicable to conversions with transparent background. (Default: 0x000000)
Simple, focused examples live in the examples/ folder:
examples/01-basic-single.jsβ Convert one static WebP to PNGexamples/02-auto-output.jsβ Let the library choose output extension (.gif for animated, .png for static)examples/03-batch-jobs.jsβ Batch conversion with per-job overridesexamples/04-transparent-color.jsβ Control GIF transparency colorexamples/99-deprecated-convert.jsβ Legacyconvert()usage (deprecated)
Run them with npm scripts:
npm run example:basic
npm run example:auto
npm run example:batch
npm run example:transparent
npm run example:deprecated # optional
# run all
npm run examples:allIf you're currently using the deprecated convert() method, here's how to migrate:
Old way (deprecated):
const converter = new webpconv();
await converter.convert('input.webp', 'output.gif', { quality: 80 });New way (recommended):
const converter = new webpconv();
await converter.convertJobs({
input: 'input.webp',
output: 'output.gif',
settings: { quality: 80 }
});Benefits of migrating:
- β Better error handling and validation
- β Batch processing capabilities
- β Auto-generated output paths
- β Per-job settings override
- β Future-proof (no deprecation warnings)
This module relies on the libwebp library for WebP image processing. Precompiled binaries of libwebp are automatically downloaded during installation.
This project is licensed under the GPL-3.0-or-later License - see the LICENSE file for details.
The libwebp library is licensed under a separate license. For more information, please refer to the libwebp license.
If you encounter any issues or have suggestions for improvements, please feel free to create an issue on the GitHub repository. Contributions in the form of pull requests are also welcome.