Convert
Change an image’s format. Transparency is flattened onto a background colour when the target format has no alpha channel.
Function
Section titled “Function”convert_image(input, &ConvertOptions) -> Vec<u8>| Language | Name |
|---|---|
| Rust | convert_image |
| JavaScript | convertImage |
| Python | convert_image |
| CLI | dusrelimage convert <input> --format webp -o out.webp |
Options
Section titled “Options”| Field | Type | Default | Meaning |
|---|---|---|---|
format |
ImageFormat | required | Jpeg, Png, WebP, Avif, Gif, Bmp. |
quality |
u8 | 80 |
Quality 1–100 for lossy targets. |
background |
Colour | white | Colour used to flatten transparency when the target has no alpha (JPEG, BMP). |
progressive |
bool | false |
Progressive JPEG / interlaced PNG output. |
Formats
Section titled “Formats”| Decode (in) | Encode (out) | |
|---|---|---|
| Supported | JPEG, PNG, WebP, GIF, BMP, TIFF | JPEG, PNG, WebP, AVIF, GIF, BMP |
| Not supported | HEIC, AVIF (input) | HEIC, TIFF |
Examples
Section titled “Examples”import { convertImage } from 'dusrelimage';
const webp = convertImage(input, { format: 'WebP', quality: 80 });const jpg = convertImage(pngWithAlpha, { format: 'Jpeg', background: '#ffffff' });from dusrelimage import convert_image
avif = convert_image(data, format="avif", quality=60)dusrelimage convert photo.png --format webp --quality 80 -o photo.webpdusrelimage convert logo.png --format jpeg --background "#000000" -o logo.jpgErrors
Section titled “Errors”| Code | When |
|---|---|
INVALID_IMAGE |
Input is not a decodable image. |
UNSUPPORTED_FORMAT |
Input format cannot be decoded, or the target cannot be encoded (e.g. HEIC). |
INVALID_QUALITY |
Quality outside 1–100. |
IMAGE_TOO_LARGE |
Over max_pixels (default 120,000,000). |
EMPTY_INPUT |
Empty input bytes. |