{"record":{"id":"cc0c17252897d527","repo":"Intervention/image","slug":"value-for-argument-setnative-native-must-be-i","errorCode":null,"errorMessage":"Value for argument setNative() \"$native\" must be instanceof of GdImage","messagePattern":"Value for argument setNative\\(\\) \"\\$native\" must be instanceof of GdImage","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Frame.php","lineNumber":53,"sourceCode":"     *\n     * @see FrameInterface::toImage()\n     */\n    public function toImage(DriverInterface $driver): ImageInterface\n    {\n        return new Image($driver, new Core([$this]));\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FrameInterface::setNative()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function setNative(mixed $native): FrameInterface\n    {\n        if (!$native instanceof GdImage) {\n            throw new InvalidArgumentException(\n                'Value for argument setNative() \"$native\" must be instanceof of ' . GdImage::class,\n            );\n        }\n\n        $this->native = $native;\n\n        return $this;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FrameInterface::native()\n     */\n    public function native(): GdImage\n    {\n        return $this->native;\n    }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Frame.php#L35-L71","documentation":"A GD Frame's native core must be a GdImage object (PHP 8's GD handle object, not a resource). setNative() throws InvalidArgumentException for anything else, guarding against legacy gd resources from pre-PHP8 style code or foreign objects like Imagick instances.","triggerScenarios":"new Frame(fopen(...)) or new Frame($binaryString) with manual frame construction; passing a raw resource left over from old GD code; mixing natives between the GD and Imagick drivers.","commonSituations":"Migrating Intervention Image v2 code that passed gd resources around, interoperability layers that shuttle native handles between libraries and drivers.","solutions":["Build the GdImage first: imagecreatefromstring($binary) or imagecreatetruecolor($w, $h)","Take natives from existing GD frames via $frame->native() instead of constructing them","Let the driver create frames (driver->createImage(), animation factories) rather than new Frame(...)"],"exampleFix":"// before\n$frame = new Frame($binaryString); // string is not a GdImage\n\n// after\n$native = imagecreatefromstring($binaryString);\n$frame = new Frame($native); // GdImage instance","handlingStrategy":"type-guard","validationCode":"if (!$native instanceof GdImage) {\n    $native = imagecreatefromstring($native); // binary string to GdImage\n}\n$frame->setNative($native);","typeGuard":"function isGdImage(mixed $value): bool\n{\n    return $value instanceof GdImage;\n}","tryCatchPattern":"try {\n    $frame->setNative($native);\n} catch (InvalidArgumentException $e) {\n    $frame->setNative(imagecreatefromstring((string) $native));\n}","preventionTips":["On PHP 8+, GD handles are GdImage objects, never resources","Take natives from existing frames or driver factory methods","Never mix natives between GD and Imagick pipelines"],"tags":["gdimage","type-check","frame","php8"],"backgroundTag":"invalid-argument-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}