{"record":{"id":"3907af2edf51bbf1","repo":"Intervention/image","slug":"invalid-limit-value-must-be-int-1-max-3907af","errorCode":null,"errorMessage":"Invalid $limit value. Must be int<1, max>","messagePattern":"Invalid \\$limit value\\. Must be int<1, max>","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Analyzers/PopularPaletteAnalyzer.php","lineNumber":28,"sourceCode":"use Intervention\\Image\\Interfaces\\ColorInterface;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\PaletteInterface;\nuse Intervention\\Image\\Interfaces\\SizeInterface;\nuse Intervention\\Image\\Traits\\CanHashColor;\n\nclass PopularPaletteAnalyzer extends AbstractPaletteAnalyzer\n{\n    use CanHashColor;\n\n    /**\n     * Create new instance.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(protected int $limit = 256, protected ?SizeInterface $region = null)\n    {\n        if ($this->limit < 1) {\n            throw new InvalidArgumentException('Invalid $limit value. Must be int<1, max>');\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see AnalyzerInterface::analyze()\n     *\n     * @throws InvalidArgumentException\n     * @throws AnalyzerException\n     */\n    public function analyze(ImageInterface $image): PaletteInterface\n    {\n        $colors = iterator_to_array($this->collectColors($image, $this->region));\n        $popular = new Palette($colors);\n\n        return $popular\n            ->reduce($this->quantizationLevels($colors))","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Analyzers/PopularPaletteAnalyzer.php#L10-L46","documentation":"resolveDriver() (used by ImageManager::__construct to build the driver from your 'driver' option) throws this InvalidArgumentException when the driver is given as a string that is not an existing class name. Intervention Image v3 expects fully-qualified driver class names such as \\Intervention\\Image\\Drivers\\Gd\\Driver::class, not short identifiers like 'gd' or 'imagick'.","triggerScenarios":"new ImageManager(['driver' => 'gd']) or 'imagick' (strings are not class names in v3); typos like 'Intervention\\Image\\Drivers\\Gd\\Drive'; using ::class on a missing import (GdDriver::class without the use statement resolves to the wrong namespace); referencing a custom driver class that is not autoloadable (wrong PSR-4 path, composer dump-autoload needed).","commonSituations":"Upgrading from Intervention Image v2 (which accepted 'gd'/'imagick' strings) to v3 without updating the config; Laravel config files caching an old driver value after upgrade; custom driver classes moved or renamed; autoload cache stale after composer changes.","solutions":["Pass the class constant: new ImageManager(['driver' => \\Intervention\\Image\\Drivers\\Gd\\Driver::class]) (or the Imagick equivalent)","Add the correct use Intervention\\Image\\Drivers\\Gd\\Driver; import at the top of the file and use Driver::class","For custom drivers, run composer dump-autoload and verify the class exists with class_exists() in a tinker/script","After fixing, clear cached config (php artisan config:clear) if the value comes from a config file"],"exampleFix":"// before (v2 style, throws in v3)\n$manager = new ImageManager(['driver' => 'gd']);\n\n// after (v3)\nuse Intervention\\Image\\Drivers\\Gd\\Driver;\n$manager = new ImageManager(['driver' => Driver::class]);","handlingStrategy":"type-guard","validationCode":"$driver = $config['driver'] ?? null;\nif (is_string($driver) && !class_exists($driver)) {\n    throw new \\RuntimeException('Unknown driver class: ' . $driver);\n}\n$manager = new \\Intervention\\Image\\ImageManager(['driver' => $driver]);","typeGuard":"use Intervention\\Image\\Interfaces\\DriverInterface;\n\n/** Normalizes user config into a valid driver class name or fails early. */\nfunction resolveDriverClass(string|DriverInterface $driver): string|DriverInterface\n{\n    if (is_object($driver)) {\n        return $driver;\n    }\n    if (!class_exists($driver)) {\n        throw new \\InvalidArgumentException('Driver class does not exist: ' . $driver);\n    }\n    return $driver;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $manager = new \\Intervention\\Image\\ImageManager(['driver' => $driverName]);\n} catch (InvalidArgumentException $e) {\n    // 'must be existing class name': fall back to a shipped driver\n    $manager = new \\Intervention\\Image\\ImageManager(\n        ['driver' => \\Intervention\\Image\\Drivers\\Gd\\Driver::class]\n    );\n}","preventionTips":["Always pass Class::class constants (Gd\\Driver::class / Imagick\\Driver::class), never bare 'gd'/'imagick' strings","Centralize driver selection in one factory/config location so v2-style values cannot leak in","Add a smoke test that constructs the manager with your configured driver during CI"],"tags":["driver","invalid-argument","class-not-found","intervention-image","v2-to-v3"],"backgroundTag":"class-not-found","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}