如何用php将图像绘制成二维码

wi3ka0sx  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(151)

在我的项目中,我试图生成一个二维码,其中包含一个基于sql表中存储的blob(1个二维码+1个logo)的图像。
我有以下代码,但似乎无法存储到我的表中的新图像。感谢您的帮助。

<?php
//for connection
$sName = "localhost";
$sUser = "Username";
$sPass = "Password";
$sDb = "Database";
$Conn = new mysqli ($sName, $sUser, $sPass, $sDb);

//variables i pass from another app
$Email = mysqli_real_escape_string($Conn, $_POST["PassEmail"]);
$qContent = addslashes(file_get_contents($_FILES["file"]["tmp_name"]));
$qOverlay = addslashes (file_get_contents($_FILES["overlay"]["tmp_name"]));

$Sql = "SELECT * FROM `userprofile_login` INNER JOIN `userprofile_personalprofile` ON userprofile_login.userid = userprofile_personalprofile.userid WHERE userprofile_login.email = '".$Email."' ";
$Result = mysqli_query($Conn, $Sql);

if (mysqli_num_rows ($Result) > 0) {
    $Row = mysqli_fetch_assoc ($Result);

    $qCheckSql = "SELECT `userid` FROM `userprofile_qr` WHERE userid = '".$Row['userid']."' ";
    $qCheckResult = mysqli_query($Conn, $qCheckSql);

    $Row2 = mysqli_fetch_assoc($qCheckResult);
    if (mysqli_num_rows ($qCheckResult) < 1) {
        //if there 0 result from previous query, insert new data
        $InsertSql = "INSERT INTO `userprofile_qr` (`userid`, `qrcode`, `overlay`)
                        VALUES ('".$Row['userid']."', '$qContent', '$qOverlay')";
        $InsertResult = mysqli_query($Conn, $InsertSql);
    } else {
        //is there ia a result from the previous query, update data
        $UpdateSql = "UPDATE `userprofile_qr` SET
                    `qrcode` = '$qContent',
                    `overlay` = '$qOverlay'
                    WHERE userid = '".$Row2['userid']."' ";
        $UpdateResult = mysqli_query($Conn, $UpdateSql);
    }

第一部分工作,问题是底部的部分,我想结合二维码和标志:

$qSql = "SELECT `qrcode`, `overlay` FROM `userprofile_qr` WHERE userid = '".$Row2['userid']."' ";
        $qSelect = mysqli_query($Conn, $qSql);

        include 'phpqrcode/qrlib.php';
        $qRow = mysqli_fetch_assoc($qSelect);

        $tImage = "<img src='data:image/png;base64,".base64_encode($qRow['qrcode'])."'/>";
        $tOverlay = "<img src='data:image/png;base64,".base64_encode($qRow['overlay'])."'/>";

        header("Content-type: image/png");
        $aQr = imagecreatefromjpeg($tImage);
        $QrWidth = imagesx($aQr);
        $QrHeight = imagesy($aQr);

        $aOverlay = imagecreatefrompng($tOverlay);
        $OverlayWidth = imagesx($aOverlay);
        $OverlayHeight = imagesy($aOverlay);

        $OverlayQrWidth = $QrWidth / 3;
        $OverlayQrHeight = $OverlayHeight / ($OverlayWidth / $OverlayQrWidth);

        imagecopyresampled($aQr, $aOverlay, $OverlayQrWidth, $OverlayQrHeight, 0, 0, $OverlayQrWidth, $OverlayQrHeight, $OverlayWidth, $OverlayHeight);
        imagepng($aQr);

        $oImage = "<img src='data:image/png;base64,".base64_encode($aQr)."'/>";

        $UpdateCombineSql = "UPDATE `userprofile_qr` SET
                        `combine` = '$oImage'
                        WHERE userid = '".$Row2['userid']."' ";
        $CombineResult = mysqli_query($Conn, $UpdateCombineSql);

        echo "Success";
    }   
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题