{"record":{"id":"af554fc6e95073f5","repo":"Intervention/image","slug":"color-channel-value-of-class-must-be-in-range-0","errorCode":null,"errorMessage":"Color channel value of {class} must be in range 0 to 1","messagePattern":"Color channel value of (.+?) must be in range 0 to 1","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/AlphaChannel.php","lineNumber":17,"sourceCode":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Intervention\\Image\\Colors;\n\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass AlphaChannel extends AbstractColorChannel\n{\n    /**\n     * @throws InvalidArgumentException\n     */\n    final public function __construct(float $value = 1)\n    {\n        if ($value < 0 || $value > 1) {\n            throw new InvalidArgumentException(\n                'Color channel value of ' . static::class . ' must be in range 0 to 1',\n            );\n        }\n\n        $this->value = (int) $this->validValueOrFail(intval(round($value * $this->max())));\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        return new static($normalized);\n    }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/AlphaChannel.php#L1-L35","documentation":"InsertModifier (watermarks) validates its $transparency float to the closed interval 0..1, where 1 is fully opaque and 0 fully transparent. Values outside — most commonly percentages like 50 or 0.5*100 mistakes — throw InvalidArgumentException in the constructor.","triggerScenarios":"$image->insert($watermark, offset-x: 0, offset-y: 0, transparency: 50); passing a 0-100 opacity value unchanged; converting '50%' opacity to 50 instead of 0.5.","commonSituations":"UI opacity sliders reporting 0-100; API docs elsewhere expressing transparency as percent; copy-pasting from libraries whose alpha is 0-127 (GD) or 0-255.","solutions":["Pass a fraction: transparency: 0.5 for 50% opacity.","Convert percent input: $transparency = $percent / 100 before insert().","Clamp when the source range is unknown: min(1, max(0, $value))."],"exampleFix":"// before\n$image->insert($watermark, transparency: 50); // throws, out of 0..1\n\n// after\n$image->insert($watermark, transparency: 50 / 100); // 0.5","handlingStrategy":"validation","validationCode":"$transparency = min(1.0, max(0.0, (float) $transparency));\n$image->insert($watermark, transparency: $transparency);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert percent sliders: divide by 100 before insert().","The scale is 0.0-1.0, unlike GD's 0-127 or common 0-255 alpha.","Clamp floats from external sources to avoid edge overshoot."],"tags":["insert","watermark","transparency","argument-validation","php"],"backgroundTag":"argument-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}