Chuyển tới nội dung chính

Format Conversion

Selecting an Output Format

Use the format parameter to convert the image to a different format on the fly.

/format=webp/https://example.com/photo.jpg

If format is not specified, the output format matches the input format - no conversion is applied.

Supported output formats

ValueDescription
webpWebP - good compression with transparency support
jpegJPEG - universal compatibility, lossy
pngPNG - lossless, supports transparency
avifAVIF - best compression, slower encoding
gifGIF - animated image support
bmpBMP - uncompressed bitmap
tiffTIFF - high-quality, lossless
icoICO - Windows icon format
jxlJPEG XL - next-gen, wide gamut support
bestAuto-select the smallest format for this image

See Best Format for details on the best value.


Quality

The q parameter controls lossy compression quality for JPEG and WebP output.

ParamTypeRangeDefault
qinteger1-100Encoder default

Higher values produce larger files with better quality. Lower values produce smaller files with more compression artifacts.

/webp,q85/https://example.com/photo.jpg
/jpeg,q70/https://example.com/photo.jpg
thông tin

The q parameter only applies to jpeg and webp output. It has no effect on lossless formats such as png, bmp, or tiff.


Format Comparison

FormatCompressionTransparencyAnimationNotes
webpGood (lossy/lossless)YesYesBroad browser support, ideal for web
avifExcellentYesYesSmaller files than WebP, slower to encode
jxlExcellentYesYesNext-gen format, wide color gamut
jpegGood (lossy)NoNoUniversal compatibility, best for photos
pngModerate (lossless)YesNoBest for graphics, logos, screenshots
gifLowPartial (1-bit)YesLegacy animated format
bmpNone (uncompressed)NoNoRaw pixels, large file size
tiffOptional (lossless)YesNoHigh-quality archival use
ico-YesNoResized to standard icon sizes
mẹo

For web use, prefer webp or avif. WebP is well-supported across all modern browsers and offers a good balance of quality and file size. AVIF provides better compression but may be slower to generate for large images.


Best Format

Use format=best to let PreviewProxy automatically pick the smallest output format for each image.

/format=best/https://example.com/photo.jpg

How it works

  1. Complexity measurement - the image is scanned with a Sobel edge detector on a downsampled thumbnail to measure edge density.
  2. Candidate selection - for complex images (many edges: photos, detailed graphics) the candidates are jpeg, webp, avif, and jxl. For simple images (flat areas, logos, illustrations) png is added as a lossless candidate.
  3. Format trial - all candidates are encoded and the one producing the smallest file is returned.

Configuration

VariableDefaultDescription
PP_BEST_FORMAT_PREFERRED_FORMATSjpeg,webp,pngFormats to trial. Add avif or jxl for better compression at the cost of slower encoding
PP_BEST_FORMAT_COMPLEXITY_THRESHOLD5.5Edge density threshold (0-100). Lossless formats (png) are excluded from candidates above this
PP_BEST_FORMAT_MAX_RESOLUTION(none)Above this megapixel count, skip the multi-encode trial and pick one format directly
PP_BEST_FORMAT_BY_DEFAULTfalseApply best-format selection when no format param is provided
PP_BEST_FORMAT_ALLOW_SKIPSfalseSkip re-encoding when best format matches the source format and no other transforms are applied

Enable by default

To make every image response use the best format without requiring format=best in the URL:

PP_BEST_FORMAT_BY_DEFAULT=true

Interaction with output disallow list

Formats listed in PP_OUTPUT_DISALLOW_LIST are excluded from the candidate set. If all candidates are disallowed, the request returns an error.

mẹo

format=best works well combined with quality: /best,q85/https://example.com/photo.jpg


ICO Output

When format=ico is specified, the image is resized to standard Windows icon dimensions before encoding. This makes it suitable for use as a favicon or application icon.

/format=ico/https://example.com/logo.png

Examples

Convert JPEG to WebP

/format=webp/https://example.com/photo.jpg

Convert to WebP with quality

/webp,q85/https://example.com/photo.jpg

Resize and convert in one request

/800x600,webp,q80/https://example.com/photo.jpg

Lossless PNG output

/format=png/https://example.com/photo.jpg

Generate a favicon

/32x32,ico/https://example.com/logo.png

High-efficiency AVIF for bandwidth savings

/avif,q75/https://example.com/photo.jpg

Auto-select the best format

/format=best/https://example.com/photo.jpg

Best format with quality

/best,q85/https://example.com/photo.jpg