PHP QR Code with Background: phpqrcode Guide
One way to add a background to a generated QR code is by using the merge method in the PHP QR Code library. Here is an example code:
require 'phpqrcode/qrlib.php';
// 生成二维码
$text = 'https://example.com';
$qrCode = QRcode::png($text, false, QR_ECLEVEL_L, 10);
// 读取背景图片
$background = imagecreatefrompng('background.png');
// 合并二维码和背景图片
imagecopy($background, $qrCode, 100, 100, 0, 0, imagesx($qrCode), imagesy($qrCode));
// 输出合并后的图片
header('Content-Type: image/png');
imagepng($background);
imagedestroy($background);
In the example code above, the QRcode::png method is first used to generate a QR code and read a background image. Then the imagecopy function is used to merge the QR code into the background image and output the merged image. Finally, the header function is used to set the output image type as PNG, and the temporary image resource is destroyed.