{"record":{"id":"c555a6efd649eaf5","repo":"Intervention/image","slug":"quality-must-be-in-range-0-to-100-c555a6","errorCode":null,"errorMessage":"Quality must be in range 0 to 100","messagePattern":"Quality must be in range 0 to 100","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Encoders/HeicEncoder.php","lineNumber":23,"sourceCode":"namespace Intervention\\Image\\Encoders;\n\nuse Intervention\\Image\\Drivers\\SpecializableEncoder;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass HeicEncoder extends SpecializableEncoder\n{\n    /**\n     * Create new encoder object.\n     *\n     * @param null|bool $strip Strip EXIF metadata\n     * @throws InvalidArgumentException\n     */\n    public function __construct(\n        public int $quality = self::DEFAULT_QUALITY,\n        public ?bool $strip = null,\n    ) {\n        if ($quality < 0 || $quality > 100) {\n            throw new InvalidArgumentException('Quality must be in range 0 to 100');\n        }\n    }\n}\n","sourceCodeStart":5,"sourceCodeEnd":27,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Encoders/HeicEncoder.php#L5-L27","documentation":"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.","triggerScenarios":"new HeicEncoder(quality: 101), new HeicEncoder(-1), or $image->save('photo.heic', quality: $configValue) where the config value is outside 0-100.","commonSituations":"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.","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"],"exampleFix":"// before\n$image->save('out.heic', quality: $request->integer('quality')); // 0-1000 from user\n\n// after\n$quality = max(0, min(100, $request->integer('quality', 75)));\n$image->save('out.heic', quality: $quality);","handlingStrategy":"validation","validationCode":"$quality = max(0, min(100, (int) $quality));\n$image->save('out.heic', quality: $quality);","typeGuard":"function isValidQuality(mixed $quality): bool\n{\n    return is_int($quality) && $quality >= 0 && $quality <= 100;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["php","intervention-image","encoder","heic","quality","invalid-argument"],"backgroundTag":"parameter-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}