Reputation: 1737
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?
Upvotes: 0
Views: 2691
Reputation: 43574
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
Upvotes: 1