gpt4 book ai didi

php - 使用 PHP QR Code Generator 在 PHP 中创建带有居中 Logo 的 QR 码

转载 作者:行者123 更新时间:2023-12-04 00:34:48 25 4
gpt4 key购买 nike

我正在使用 PHP QR 码 ( http://phpqrcode.sourceforge.net/ ) 创建 QR 码。它运行良好,但现在我需要一个自由空间来放置其中心的自定义图形或 Logo 。我想在不将图像保存在服务器上的情况下执行此操作。有人有建议吗?到目前为止我得到的是:

<?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 );
?>

最佳答案

好的,我找到了解决方案。在临时创建图像文件的位置插入 Logo 或您想要的任何内容。我只是对此处找到的代码进行了非常小的改动 http://ourcodeworld.com/articles/read/225/how-to-generate-qr-code-with-logo-easily-in-php-automatically我在最后使用 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);
?>

关于php - 使用 PHP QR Code Generator 在 PHP 中创建带有居中 Logo 的 QR 码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45520988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com