{"record":{"id":"3b63ba0e3edd004f","repo":"Intervention/image","slug":"quality-must-be-in-range-0-to-100","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/AvifEncoder.php","lineNumber":23,"sourceCode":"namespace Intervention\\Image\\Encoders;\n\nuse Intervention\\Image\\Drivers\\SpecializableEncoder;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass AvifEncoder 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/AvifEncoder.php#L5-L27","documentation":"InvalidArgumentException from the AvifEncoder constructor: quality is validated to be an integer in the inclusive range 0-100, and anything outside is rejected immediately at construction time, before any encoding happens. The same 0-100 percent contract applies to the other quality-taking encoders in this library.","triggerScenarios":"new AvifEncoder(quality: 150) or quality: -1; in practice $image->encode(new AvifEncoder(quality: (int) $request->input('quality'))) with unchecked user input, or config values ported from tools that use a different scale.","commonSituations":"User-supplied quality from forms/APIs passed through unchecked; environment variables or configs written for a 0-1 or 0-10 scale (ffmpeg crf, some encoders); arithmetic that adds a margin to an already-maximal 100.","solutions":["Clamp before constructing: $quality = max(0, min(100, (int) $quality))","Validate the range at the request boundary and reject out-of-range input early","Check for scale confusion - this library uses 0-100 percent, not 0-1 or crf-style values","Use the named argument (quality: 85) to avoid positional-argument mix-ups with strip"],"exampleFix":"// before\n$encoded = $image->encode(new AvifEncoder(150));\n\n// after\n$quality = max(0, min(100, (int) $config['quality']));\n$encoded = $image->encode(new AvifEncoder(quality: $quality));","handlingStrategy":"validation","validationCode":"$quality = max(0, min(100, (int) $input['quality']));\n$encoded = $image->encode(new AvifEncoder(quality: $quality));","typeGuard":"function isValidQuality(mixed $quality): bool\n{\n    return is_int($quality) && $quality >= 0 && $quality <= 100;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException as ImageInvalidArgumentException;\n\ntry {\n    $encoder = new AvifEncoder(quality: $quality);\n} catch (ImageInvalidArgumentException $e) {\n    $encoder = new AvifEncoder(); // fall back to default quality\n}","preventionTips":["Clamp quality at the request boundary before it reaches any encoder","Validate config/env quality values with a 0-100 rule in a startup check","Remember this library's scale is 0-100 percent, unlike 0-1 ratios or crf values"],"tags":["avif","encoder","quality","argument-validation"],"backgroundTag":"value-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}