some1 some1 - 2 years ago 132
PHP Question

Error: imagecopymerge() expects parameter 2 to be resource

Getting an error trying to set an image as a variable in PHP:

$barcode= 'barcode_test.png';
$image = ImageCreate($width, $height);

PHP Warning: imagecopymerge() expects parameter 2 to be resource, string given

How do I make
a resource, not a string?

Answer Source

In your case you have to use imagecreatefrompng to get a resource of the file. Try the following:

$barcode = imagecreatefrompng('barcode_test.png');
$image = ImageCreate($width, $height);

If you are using another file type you have to choose one of the following function depending on the extension: imagecreatefromgd2, imagecreatefromgd2part, imagecreatefromgd, imagecreatefromgif, imagecreatefromjpeg, imagecreatefrompng, imagecreatefromstring, imagecreatefromwbmp, imagecreatefromwebp, imagecreatefromxbm, imagecreatefromxpm

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download