{"record":{"id":"f0a3f50b2798af02","repo":"Intervention/image","slug":"percentage-value-must-be-between-100-and-100","errorCode":null,"errorMessage":"Percentage value must be between -100 and 100","messagePattern":"Percentage value must be between -100 and 100","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/AbstractColorChannel.php","lineNumber":42,"sourceCode":"    {\n        return round(($this->value() - $this->min()) / ($this->max() - $this->min()), $precision);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorChannelInterface::scale()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function scale(int $percent): self\n    {\n        if ($percent === 0) {\n            return $this;\n        }\n\n        if ($percent < -100 || $percent > 100) {\n            throw new InvalidArgumentException('Percentage value must be between -100 and 100');\n        }\n\n        $normalized = $this->normalized();\n        $base = $percent >= 0 ? (1 - $normalized) : $normalized;\n        $scaled = min(1.0, max(0.0, $normalized + $base / 100 * $percent));\n        $this->value = static::fromNormalized($scaled)->value();\n\n        return $this;\n    }\n\n    /**\n     * Throw exception if the given value is not applicable for channel\n     * otherwise the value is returned unchanged.\n     *\n     * @throws InvalidArgumentException\n     */\n    protected function validValueOrFail(int|float $value): mixed\n    {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/AbstractColorChannel.php#L24-L60","documentation":"When the colorspace target is a string that is not a class name, ColorspaceModifier matches it against the supported list: rgb/srgb/rgba/srgba, cmyk, hsl, hsv/hsb, oklab, oklch. Anything else — including differently-cased strings, since the match is case-sensitive — throws NotSupportedException with the terse 'Colorspace is not supported by driver'.","triggerScenarios":"$image->colorspace('CMYK') (uppercase), $image->colorspace('gray'), $image->colorspace('s-RGB'), or any misspelling; values arriving from user input or config files unnormalized.","commonSituations":"Uppercase values from print-industry tooling; 'gray'/'greyscale' expectations carried over from other libraries (ImageMagick names); config keys written by hand.","solutions":["Use lowercase canonical strings: 'rgb', 'cmyk', 'hsl', 'hsv', 'oklab', 'oklch', or pass Colorspace class names like Rgb::class.","Normalize user input: $target = strtolower(trim($target)) before calling ->colorspace($target).","Map exotic names yourself ('greyscale' => 'rgb') instead of forwarding them.","Catch NotSupportedException to give a helpful message listing valid values."],"exampleFix":"// before\n$image->colorspace($request->string('colorspace')); // 'CMYK' throws\n\n// after\n$target = strtolower(trim($request->string('colorspace')));\n$image->colorspace(match (true) {\n    str_starts_with($target, 'cmyk') => 'cmyk',\n    default => 'rgb',\n});","handlingStrategy":"validation","validationCode":"$target = strtolower(trim($target));\n$valid = ['rgb', 'srgb', 'rgba', 'srgba', 'cmyk', 'hsl', 'hsv', 'hsb', 'oklab', 'oklch'];\nif (!in_array($target, $valid, true)) {\n    throw new InvalidArgumentException('Unknown colorspace: ' . $target);\n}\n$image->colorspace($target);","typeGuard":null,"tryCatchPattern":"try {\n    $image->colorspace($target);\n} catch (Intervention\\Image\\Exceptions\\NotSupportedException $e) {\n    // default to 'rgb' and warn\n}","preventionTips":["Lowercase and trim any string before ->colorspace().","Map domain names ('greyscale', 'CMYK') to supported values yourself.","Note the match is case-sensitive: only lowercase strings are accepted."],"tags":["colorspace","string-validation","modifier","php"],"backgroundTag":"unsupported-colorspace","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}