{"record":{"id":"c669ddfd4cb24061","repo":"Intervention/image","slug":"quality-must-be-in-range-0-to-100-c669dd","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/Jpeg2000Encoder.php","lineNumber":23,"sourceCode":"namespace Intervention\\Image\\Encoders;\n\nuse Intervention\\Image\\Drivers\\SpecializableEncoder;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass Jpeg2000Encoder 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/Jpeg2000Encoder.php#L5-L27","documentation":"Jpeg2000Encoder validates its $quality constructor option and throws InvalidArgumentException unless it is an integer between 0 and 100 inclusive. The value arrives either directly via new Jpeg2000Encoder(quality: N) or through option forwarding from $image->save('out.jp2', quality: N) / encodeUsingPath(). The range check happens in the shared constructor before driver specialization, so it throws on any driver even though JPEG 2000 output needs Imagick.","triggerScenarios":"new Jpeg2000Encoder(150), new Jpeg2000Encoder(quality: -10), or $image->encodeUsingPath('scan.jp2', quality: $value) with $value outside 0-100.","commonSituations":"Quality configured from a settings panel or .env entry that was never range-validated; unit-to-unit scaling bugs that produce values above 100; negative quality from misconfigured defaults.","solutions":["Clamp the quality: $quality = max(0, min(100, $quality))","Add validation rules for any quality value coming from users or configuration","If a fractional 0-1 scale is used internally, convert it explicitly: (int) round($ratio * 100)"],"exampleFix":"// before\n$enc = new Jpeg2000Encoder(quality: $ratio * 100 * 100); // double scaling -> 10000\n\n// after\n$enc = new Jpeg2000Encoder(quality: (int) round(max(0, min(1, $ratio)) * 100));","handlingStrategy":"validation","validationCode":"$quality = max(0, min(100, (int) $quality));\n$image->save('scan.jp2', quality: $quality);","typeGuard":"function isValidQuality(mixed $quality): bool\n{\n    return is_int($quality) && $quality >= 0 && $quality <= 100;\n}","tryCatchPattern":null,"preventionTips":["Range-check job payloads and config values before encoding","Convert 0-1 scales explicitly to the 0-100 scale","Remember quality applies identically across all format encoders"],"tags":["php","intervention-image","encoder","jpeg2000","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"}