some1 some1 - 1 year ago 55
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?


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