Skip to content

Convert

Change an image’s format. Transparency is flattened onto a background colour when the target format has no alpha channel.

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
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.
Decode (in) Encode (out)
Supported JPEG, PNG, WebP, GIF, BMP, TIFF JPEG, PNG, WebP, AVIF, GIF, BMP
Not supported HEIC, AVIF (input) HEIC, TIFF
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)
Terminal window
dusrelimage convert photo.png --format webp --quality 80 -o photo.webp
dusrelimage convert logo.png --format jpeg --background "#000000" -o logo.jpg
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.