getzola/zola · error

Quality for JPEG must be between {} and {} (inclusive); {} i

Error message

Quality for JPEG must be between {} and {} (inclusive); {} is not valid

What it means

`ImageFormat::from_args` validates the `--quality` argument when the output format is JPEG. JPEG quality must be an integer within the inclusive range QUALITY_MIN_JPEG..=QUALITY_MAX_JPEG (1..=100); anything outside raises this error naming the valid bounds and the offending value.

Source

Thrown at components/imageproc/src/format.rs:44

impl Format {
    pub fn from_args(
        is_lossy: bool,
        format: &str,
        quality: Option<u8>,
        speed: Option<u8>,
    ) -> Result<Format> {
        use Format::*;
        let format_from_auto = match (format, is_lossy) {
            ("auto", true) => "jpeg",
            ("auto", false) => "png",
            (other_format, _) => other_format,
        };
        match format_from_auto {
            "jpeg" | "jpg" => match quality.unwrap_or(DEFAULT_QUALITY_JPEG) {
                valid_quality @ QUALITY_MIN_JPEG..=QUALITY_MAX_JPEG => {
                    Ok(Jpeg { quality: valid_quality })
                }
                invalid_quality => Err(anyhow!(
                    "Quality for JPEG must be between {} and {} (inclusive); {} is not valid",
                    QUALITY_MIN_JPEG,
                    QUALITY_MAX_JPEG,
                    invalid_quality
                )),
            },
            "png" => Ok(Png),
            "webp" => match quality {
                Some(QUALITY_MIN_WEBP..=QUALITY_MAX_WEBP) | None => Ok(WebP { quality }),
                Some(invalid_quality) => Err(anyhow!(
                    "Quality for WebP must be between {} and {} (inclusive); {} is not valid",
                    QUALITY_MIN_WEBP,
                    QUALITY_MAX_WEBP,
                    invalid_quality
                )),
            },
            "avif" => {
                let q = match quality.unwrap_or(DEFAULT_QUALITY_AVIF) {

View on GitHub (pinned to 61d3082821)

Solutions

  1. Pass an integer quality between 1 and 100, e.g. `--quality 80`
  2. Remove the `--quality` flag to use the built-in JPEG default (DEFAULT_QUALITY_JPEG)
  3. Convert fractional quality (0-1) to percent (multiply by 100 and round)

Example fix

// before
$ zola image --format jpg --quality 0.8 in.png out.jpg
// after
$ zola image --format jpg --quality 80 in.png out.jpg
Defensive patterns

Strategy: validation

Validate before calling

if let Some(q) = quality {
    if !(1..=100).contains(&q) {
        return Err(format!("JPEG quality must be 1-100, got {}", q));
    }
}

Type guard

fn is_valid_jpeg_quality(q: u8) -> bool { (1..=100).contains(&q) }

Try / catch

match ImageFormat::from_args(format, quality, speed) {
    Ok(f) => f,
    Err(e) if e.to_string().contains("Quality for JPEG") => {
        eprintln!("Use an integer 1-100 for JPEG quality");
        ImageFormat::Jpeg { quality: 75 }
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Running `zola image --quality <n> --format jpeg|jpg` (or equivalent imageproc API) where n < 1 or n > 100 (or otherwise outside the JPEG bounds, e.g. 0 or 150).

Common situations: Using a 0.0-1.0 float quality convention (e.g. 0.8) from other tools; typos like 500; reusing WebP/AVIF decimal quality values; forgetting that quality must be an integer here.

Related errors


AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/80cbda44381c0728. Report an issue: GitHub.