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
WebpEncoder validates its $quality constructor option and throws InvalidArgumentException unless it is an integer between 0 and 100. The value arrives directly via new WebpEncoder(quality: N) or through forwarded options, e.g. $image->save('out.webp', quality: N) -> FilePathEncoder -> Format::encoder(...$options) -> new WebpEncoder(...).
Source
Thrown at src/Encoders/WebpEncoder.php:23
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class WebpEncoder 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 quality into 0-100 before passing: max(0, min(100, $quality))
- Add request validation (e.g. 'integer|between:0,100') for any quality parameter
- Audit WebP presets in config files and correct out-of-range values
Example fix
// before
$image->toWebp(quality: $request->query('q')); // ?q=150 crashes
// after
$image->toWebp(quality: max(0, min(100, (int) $request->query('q', 82)))); Defensive patterns
Strategy: validation
Validate before calling
$quality = max(0, min(100, (int) $request->query('q', 82)));
$image->toWebp(quality: $quality); Type guard
function isValidQuality(mixed $quality): bool
{
return is_int($quality) && $quality >= 0 && $quality <= 100;
} Prevention
- Clamp query/API quality parameters before use
- Cap quality presets in config validation
- Remember the same 0-100 rule applies to every quality-aware encoder
When it happens
Trigger: new WebpEncoder(quality: 120), new WebpEncoder(-1), or $image->encodeUsingPath('thumb.webp', quality: $userInput) with out-of-range input.
Common situations: WebP conversion endpoints that forward a client-supplied quality parameter without validation; image-optimization configs tuned above 100 in an attempt to force maximum fidelity; quality defaults that drifted after config refactors.
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/bd628fef4f2195d6.
Report an issue: GitHub.