some1 some1 - 7 months ago 6
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);
ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);



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


How do I make
$barcode
a resource, not a string?

Answer

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);
ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);

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

Comments