Set output quality (1–100) without specifying a format. Applied to whatever format is active at output time. Use format-specific methods when you need fine-grained control.
await img('photo.jpg').quality(75).toBuffer()
await img('photo.jpg').quality(75).toBuffer()
JPEG
Option
Type
Default
Description
quality
number
80
Quality 1–100. Lower = smaller file.
progressive
boolean
false
Progressive (interlaced) JPEG — loads top-to-bottom in browsers.
mozjpeg
boolean
false
Use MozJPEG encoder for better compression at same quality.
// Standard qualityawait img('photo.jpg').jpeg({ quality: 85 }).toBuffer()// Progressive JPEG for webawait img('photo.jpg').jpeg({ quality: 80, progressive: true }).toBuffer()// Maximum compression with MozJPEGawait img('photo.jpg').jpeg({ quality: 75, mozjpeg: true }).toBuffer()
// Standard qualityawait img('photo.jpg').jpeg({ quality: 85 }).toBuffer()// Progressive JPEG for webawait img('photo.jpg').jpeg({ quality: 80, progressive: true }).toBuffer()// Maximum compression with MozJPEGawait img('photo.jpg').jpeg({ quality: 75, mozjpeg: true }).toBuffer()
// Standard AVIFawait img('photo.jpg').avif({ quality: 50 }).toBuffer()// High qualityawait img('photo.jpg').avif({ quality: 70, effort: 6 }).toBuffer()// Maximum compression (slow)await img('photo.jpg').avif({ quality: 40, effort: 9 }).toBuffer()
// Standard AVIFawait img('photo.jpg').avif({ quality: 50 }).toBuffer()// High qualityawait img('photo.jpg').avif({ quality: 70, effort: 6 }).toBuffer()// Maximum compression (slow)await img('photo.jpg').avif({ quality: 40, effort: 9 }).toBuffer()
AVIF achieves 40–50% smaller files than JPEG but encoding is significantly slower than WebP. Use it for static assets where build-time encoding is acceptable.
Format comparison
Format
Best for
Typical savings vs JPEG
JPEG
Photos, no transparency
baseline
PNG
Graphics, transparency, lossless
larger
WebP
Web images, photos + graphics
25–35% smaller
AVIF
Maximum compression, modern browsers
40–50% smaller
Examples
// Convert to WebP at 85% qualityawait img('photo.jpg').webp({ quality: 85 }).toBuffer()// Convert PNG to AVIFawait img('graphic.png').avif({ quality: 60 }).toBuffer()// Resize then encodeawait img('photo.jpg') .resize(1200) .webp({ quality: 85, effort: 5 }) .toBuffer()// Generic format methodawait img('photo.jpg').format('webp', { quality: 80 }).toBuffer()
// Convert to WebP at 85% qualityawait img('photo.jpg').webp({ quality: 85 }).toBuffer()// Convert PNG to AVIFawait img('graphic.png').avif({ quality: 60 }).toBuffer()// Resize then encodeawait img('photo.jpg') .resize(1200) .webp({ quality: 85, effort: 5 }) .toBuffer()// Generic format methodawait img('photo.jpg').format('webp', { quality: 80 }).toBuffer()