Intervention/image · error · InvalidArgumentException

Quality must be in range 0 to 100

Error message

Quality must be in range 0 to 100

What it means

TiffEncoder validates its $quality constructor option and throws InvalidArgumentException unless it is an integer in the range 0-100. The value arrives directly via new TiffEncoder(quality: N) or through option forwarding from $image->save('out.tiff', quality: N) / encodeUsingPath(), which resolve the TIFF encoder from the extension and pass your options to its constructor.

Source

Thrown at src/Encoders/TiffEncoder.php:23

namespace Intervention\Image\Encoders;

use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;

class TiffEncoder extends SpecializableEncoder
{
    /**
     * Create new encoder object.
     *
     * @param null|bool $strip Strip EXIF metadata
     * @throws InvalidArgumentException
     */
    public function __construct(
        public int $quality = self::DEFAULT_QUALITY,
        public ?bool $strip = null,
    ) {
        if ($quality < 0 || $quality > 100) {
            throw new InvalidArgumentException('Quality must be in range 0 to 100');
        }
    }
}

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Clamp the value: max(0, min(100, $quality))
  2. Validate quality in the job/config layer before it reaches the encoder
  3. Add an assertion or unit test that your configured quality constant stays within 0-100

Example fix

// before
$encoder = new TiffEncoder(quality: $job->quality); // payload may carry any int

// after
$encoder = new TiffEncoder(quality: max(0, min(100, (int) $job->quality)));
Defensive patterns

Strategy: validation

Validate before calling

$quality = max(0, min(100, (int) $quality));
$image->save('scan.tiff', quality: $quality);

Type guard

function isValidQuality(mixed $quality): bool
{
    return is_int($quality) && $quality >= 0 && $quality <= 100;
}

Prevention

When it happens

Trigger: new TiffEncoder(quality: 105), new TiffEncoder(-2), or $image->save('scan.tiff', quality: $value) with the value outside 0-100.

Common situations: Scan/archival pipelines where quality comes from unvalidated job payloads or environment configuration; values above 100 ported from tools that treat larger numbers as higher quality; negative numbers from defaults arithmetic.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/0a139801168409c4. Report an issue: GitHub.