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
JxlEncoder validates its $quality constructor option and throws InvalidArgumentException unless it is an integer from 0 to 100. Options are forwarded from the generic APIs, so $image->save('out.jxl', quality: N) reaches this constructor via Format::encoder(...$options). The range check runs in the shared constructor before driver specialization, so it fires even on the GD driver, although JXL output ultimately requires Imagick.
Source
Thrown at src/Encoders/JxlEncoder.php:23
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class JxlEncoder 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
- Clamp the value into range: max(0, min(100, $quality))
- Validate quality where it enters your application (form request, DTO, config loader)
- Confirm any 0-1 float scale is converted before passing: (int) round($f * 100)
Example fix
// before
$image->save('out.jxl', quality: $settings['img_quality']); // config says 120
// after
$image->save('out.jxl', quality: (int) clamp((int) $settings['img_quality'], 0, 100)); Defensive patterns
Strategy: validation
Validate before calling
$quality = max(0, min(100, (int) $quality));
$image->save('out.jxl', quality: $quality); Type guard
function isValidQuality(mixed $quality): bool
{
return is_int($quality) && $quality >= 0 && $quality <= 100;
} Prevention
- Validate persisted settings before passing them as encoder options
- Watch for unit-scaling bugs (0-1 floats, double multiplication by 100)
- Keep quality values in a dedicated validated config path
When it happens
Trigger: new JxlEncoder(quality: 110), new JxlEncoder(-1), or $image->encodeUsingPath('photo.jxl', quality: $value) with the value outside 0-100.
Common situations: Unvalidated quality from client requests or stored settings; scaled percentages exceeding 100; porting code from libraries that accept quality above 100 or a 0-1 float scale.
Related errors
- Quality must be in range 0 to 100
- Quality must be in range 0 to 100
- Quality must be in range 0 to 100
- Quality must be in range 0 to 100
- Quality must be in range 0 to 100
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/81cc41ef2fbf770c.
Report an issue: GitHub.