{"record":{"id":"a0d68720d15d12ee","repo":"Intervention/image","slug":"failed-to-import-color","errorCode":null,"errorMessage":"Failed to import color","messagePattern":"Failed to import color","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/ColorProcessor.php","lineNumber":103,"sourceCode":"\n            $r = $color['red'];\n            $g = $color['green'];\n            $b = $color['blue'];\n            $a = $color['alpha'];\n        } else {\n            // integer conversion\n            $a = ($color >> 24) & 0xFF;\n            $r = ($color >> 16) & 0xFF;\n            $g = ($color >> 8) & 0xFF;\n            $b = $color & 0xFF;\n        }\n\n        try {\n            // convert gd apha integer to intervention alpha integer\n            // ([opaque]0-127[transparent]) to ([opaque]1-0[transparent])\n            $a = self::convertRange($a, 127, 0, 0, 1);\n        } catch (RuntimeException $e) {\n            throw new DriverException('Failed to import color', previous: $e);\n        }\n\n        try {\n            return new Color($r, $g, $b, $a);\n        } catch (InvalidArgumentException $e) {\n            throw new DriverException('Failed to import color', previous: $e);\n        }\n    }\n\n    /**\n     * Check if given array is valid color format\n     * array{red: int, green: int, blue: int, alpha: int}\n     * i.e. result of imagecolorsforindex()\n     *\n     * @param array<mixed> $color\n     */\n    private function isValidArrayColor(array $color): bool\n    {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/ColorProcessor.php#L85-L121","documentation":"After extracting r/g/b and the GD alpha (0-127) from the int or array input, import() remaps alpha to [0..1] with convertRange($a, 127, 0, 0, 1). That helper only throws RuntimeException on a degenerate range (division by zero when min == max, src/Traits/CanConvertRange.php:27-28); with the fixed constants 127 and 0 it cannot. This DriverException is therefore a defensive, effectively unreachable guard kept to wrap any future range failure.","triggerScenarios":"Not reproducible through the public import() with any int or valid-shape array input; a theoretical guard only meaningful for library maintainers or forks that alter the constants.","commonSituations":"Appears only in test suites enumerating every documented @throws branch; users seeing it should suspect a patched/forked vendor directory.","solutions":["If you encounter it, check that vendor/intervention/image is unmodified: composer validate && composer install --prefer-source to diff","Report it upstream with a reproducer, since stock code paths cannot trigger it","Handle like any DriverException: catch, log ->getPrevious() for the wrapped RuntimeException"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\DriverException;\n\ntry {\n    $color = $processor->import($gdValue);\n} catch (DriverException $e) {\n    // unreachable in stock code; check vendor integrity if this fires\n    throw $e;\n}","preventionTips":["Keep vendor/intervention/image unmodified; verify with composer install on CI","If it ever fires, capture ->getPrevious() for the wrapped RuntimeException and report upstream"],"tags":["gd","color","import","defensive","unreachable"],"backgroundTag":"color-conversion-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}