使用PHP二维码生成器在PHP中创建带有居中徽标的二维码
我正在使用PHP QR代码()创建QR代码。它运作良好,但现在我需要一个自由的空间为一个自定义的图形或标志在它的中心。我想在不将映像保存到服务器上的情况下执行此操作。有人有什么建议吗?到目前为止,我得到的是:使用PHP二维码生成器在PHP中创建带有居中徽标的二维码,php,qr-code,Php,Qr Code,我正在使用PHP QR代码()创建QR代码。它运作良好,但现在我需要一个自由的空间为一个自定义的图形或标志在它的中心。我想在不将映像保存到服务器上的情况下执行此操作。有人有什么建议吗?到目前为止,我得到的是: <?php $param = $_GET['projectid']; $divider = ","; $codeText = 'Projectname'.$divider.$param; // outputs image directly
<?php
$param = $_GET['projectid'];
$divider = ",";
$codeText = 'Projectname'.$divider.$param;
// outputs image directly into browser, as PNG stream
//QRcode::png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)
QRcode::png($codeText, false, QR_ECLEVEL_H, 9, 2, true );
?>
好的,我找到了一个解决方案。临时创建图像文件以插入徽标或任何您想要的内容。我不仅仅是这里代码的一个很小的改变 最后我使用readfile()将所有内容直接推送到输出缓冲区
<?php
// user input
$param = $_GET['projectid'];
$divider = ",";
// Path where the images will be saved
$filepath = 'content/images/qr/qr-temp-image.png';
// Image (logo) to be drawn
$logopath = 'content/images/qr/qr-freespace.png';
// we need to be sure ours script does not output anything!!!
// otherwise it will break up PNG binary!
ob_start("callback");
// text for the qr code
$codeText = 'Projectname'.$divider.$param;
// end of processing here
$debugLog = ob_get_contents();
ob_end_clean();
// create a QR code and save it in the filepath
QRcode::png($codeText, $filepath, QR_ECLEVEL_H, 9, 2, true );
// Start DRAWING LOGO IN QRCODE
$QR = imagecreatefrompng($filepath);
// START TO DRAW THE IMAGE ON THE QR CODE
$logo = imagecreatefromstring(file_get_contents($logopath));
$QR_width = imagesx($QR);
$QR_height = imagesy($QR);
$logo_width = imagesx($logo);
$logo_height = imagesy($logo);
// Scale logo to fit in the QR Code
$logo_qr_width = $QR_width/3;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
imagecopyresampled($QR, $logo, $QR_width/3, $QR_height/3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
// Save QR code again, but with logo on it
imagepng($QR,$filepath);
// outputs image directly into browser, as PNG stream
readfile($filepath);
?>
徽标未对准二维码的中心。logo width=234px,height=107pxHi您想给我看一下您的代码和使用过的图像吗?也许我能看出问题的原因。你试过不同大小的二维码吗?我不确定,但也许你的234像素宽的徽标太大了,或者是9号的二维码?在这里尝试一个更高的数字QRcode::png($codeText,$filepath,QR\u ECLEVEL\u H,12,2,true)。