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
HeicEncoder validates its $quality constructor option and throws InvalidArgumentException unless it is an integer in the inclusive range 0-100. The option reaches this constructor either directly (new HeicEncoder(quality: N)) or indirectly, because generic APIs forward options to the format's encoder: $image->save('out.heic', quality: N) -> FilePathEncoder -> Format::encoder(...$options) -> new HeicEncoder(...). The check runs in the shared constructor, so it fires regardless of driver, even though HEIC encoding itself requires the Imagick driver.
Source
Thrown at src/Encoders/HeicEncoder.php:23
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class HeicEncoder 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 before passing it: max(0, min(100, $quality))
- Validate user-supplied quality at the input boundary (request validation rules like 'integer|between:0,100' in Laravel)
- Double-check config values such as IMAGE_QUALITY and fix any entry outside 0-100
Example fix
// before
$image->save('out.heic', quality: $request->integer('quality')); // 0-1000 from user
// after
$quality = max(0, min(100, $request->integer('quality', 75)));
$image->save('out.heic', quality: $quality); Defensive patterns
Strategy: validation
Validate before calling
$quality = max(0, min(100, (int) $quality));
$image->save('out.heic', quality: $quality); Type guard
function isValidQuality(mixed $quality): bool
{
return is_int($quality) && $quality >= 0 && $quality <= 100;
} Prevention
- Clamp quality at the boundary where user or config input enters
- Add request validation rules (integer, between:0,100)
- Use a single shared constant/helper for quality so all call sites stay in range
When it happens
Trigger: new HeicEncoder(quality: 101), new HeicEncoder(-1), or $image->save('photo.heic', quality: $configValue) where the config value is outside 0-100.
Common situations: Quality taken from an HTTP request, environment variable or config file without bounds checking; percentage arithmetic that scales past 100 (e.g. multiplying an already-percent value by 100 again); negative values produced by subtraction logic.
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/c555a6efd649eaf5.
Report an issue: GitHub.