Constructor
new Converter(defaultOptionsopt)
Creates a new Converter instance.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
defaultOptions | ConverterOptions | <optional> | {} | Default options for conversions |
- Source
Example
const Converter = require('@caed0/webp-conv');
const conv = new Converter({ quality: 80, transparent: '0x000000' });Methods
(async) convert(input, output, optionsopt, suppressWarningopt) → {Promise.<string>}
Convert a single WebP file to GIF or PNG format.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input | string | Path to input WebP file | ||
output | string | Path to output file (.gif or .png) | ||
options | ConverterOptions | <optional> | {} | Conversion options |
suppressWarning | boolean | <optional> | false | Internal flag to suppress the deprecation warning |
- Deprecated
- Use
Converter#convertJobsfor job-based processing.
- Use
- Source
Throws:
If validation fails or conversion errors occur
- Type
- Error
Returns:
Path to converted file
- Type:
- Promise.<string>
Example
// Convert animated WebP to GIF
await converter.convert('input.webp', 'output.gif', { quality: 80 });
// Convert static WebP to PNG
await converter.convert('static.webp', 'output.png');(async) convertJobs(jobs) → {Promise.<(string|Array.<string>)>}
Convert WebP files using job objects.
- Source
Throws:
When jobs are missing/invalid or input is not a WebP
- Type
- Error
Returns:
Output path(s) of converted file(s)
- Type:
- Promise.<(string|Array.<string>)>
Example
// Single job
await converter.convertJobs({
input: 'path/to/input.webp',
output: 'path/to/output.gif',
settings: { quality: 80 }
});
// Multiple jobs
await converter.convertJobs([
{ input: 'file1.webp', settings: { quality: 90 } },
{ input: 'file2.webp', output: 'custom.png' }
]);