{"record":{"id":"599eff5f1281e7d9","repo":"Intervention/image","slug":"normalized-color-channel-value-must-be-between-0-t","errorCode":null,"errorMessage":"Normalized color channel value must be between 0 to 1","messagePattern":"Normalized color channel value must be between 0 to 1","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/FloatColorChannel.php","lineNumber":29,"sourceCode":"    /**\n     * @throws InvalidArgumentException\n     */\n    final public function __construct(float $value)\n    {\n        $this->value = (float) $this->validValueOrFail($value);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorChannelInterface::fromNormalized()\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function fromNormalized(float $normalized): self\n    {\n        if ($normalized < 0 || $normalized > 1) {\n            throw new InvalidArgumentException(\n                'Normalized color channel value must be between 0 to 1',\n            );\n        }\n\n        return new static(static::min() + $normalized * (static::max() - static::min()));\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorChannelInterface::value()\n     */\n    public function value(): float\n    {\n        return (float) $this->value;\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/FloatColorChannel.php#L11-L47","documentation":"FloatColorChannel::fromNormalized() maps a value in the closed interval [0.0, 1.0] onto the channel's internal range, and rejects anything outside it. This is the base factory for float channels such as alpha, so the check fires whenever a 'normalized' value is actually a percentage (e.g. 50 instead of 0.5), a negative number, or a float that drifted slightly past 1.0 through arithmetic.","triggerScenarios":"Calling Alpha::fromNormalized(50) after forgetting to divide a percentage by 100; passing a ratio computed as $part / $total when $total is 0 (gives NAN) or when the parts sum to more than the total (ratio > 1); accumulating float rounding like 0.1 + 0.2 * 5 yielding 1.0000000000000002.","commonSituations":"Mixing up percent (0-100) and normalized (0-1) scales when bridging UI sliders, database values, or CSS percentages into the library; unvalidated external input; statistical normalization code where sums can exceed the divisor due to rounding.","solutions":["Divide percentages by 100 before calling fromNormalized()","Clamp before calling: $value = min(1.0, max(0.0, $value))","Guard division: if ($total <= 0) { $ratio = 0.0; } else { $ratio = $part / $total; }","Round tiny float artifacts: $value = round($value, 6) before the call"],"exampleFix":"// before\n$alpha = Alpha::fromNormalized($userOpacity * 100); // 0-100 scale passed as normalized\n\n// after\n$alpha = Alpha::fromNormalized($userOpacity); // already 0.0-1.0\n// or convert explicitly:\n$alpha = Alpha::fromNormalized($percent / 100);","handlingStrategy":"validation","validationCode":"$normalized = min(1.0, max(0.0, $normalized));\nif (!is_finite($normalized)) {\n    $normalized = 0.0;\n}\n$channel = Alpha::fromNormalized($normalized);","typeGuard":"function isNormalizedValue(mixed $value): bool\n{\n    return is_float($value) && is_finite($value) && $value >= 0.0 && $value <= 1.0;\n}","tryCatchPattern":null,"preventionTips":["Decide on ONE alpha scale (0.0-1.0) across your domain and convert at the edges","Clamp after any ratio math: min(1.0, max(0.0, $ratio))","Guard divisions by zero before computing normalized values"],"tags":["php","intervention-image","color","alpha","range-validation","normalized-value"],"backgroundTag":"argument-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}