首页 > 解决方案 > 生成二维码并合并到编辑后的 ​​JPG 文件中

问题描述

我的要求很简单。有一个JPG文件。一些文本被引入其中。生成二维码并保存为 png 文件。此 PNG 文件与 JPG 文件合并。输出的 JPG 图像不包含二维码。我在某个地方错了,但我不知道在哪里。这是我的代码:

ini_set('memory_limit', '64M');
$jpg_image = imagecreatefromjpeg('certificate.jpg');
if ($jpg_image) {
    $text = $name;
    $textc = imagecolorallocate($jpg_image, 0, 0, 0);
    $font_path = '../images/CHOPS___.TTF';
    imagettftext($jpg_image, 42, 0, 300, 400, $textc, $font_path, $text);
    include('phpqrcode/qrlib.php');
    $tempDir = 'temp/';
    $fileName = 'tmp_'.md5($reg).'.png';
    $pngAbsoluteFilePath = $tempDir.$fileName;
    if (!file_exists($pngAbsoluteFilePath)) {
        QRcode::png($text, $pngAbsoluteFilePath);
        $qrcode = imagecreatefrompng($pngAbsoluteFilePath); 
        imagecopymerge($jpg_image, $qrcode, 10, 10, 0, 0, 100, 47, 75);
    }
    header('Content-Type: image/jpeg');
    imagejpeg($jpg_image);
    imagedestroy($jpg_image);

标签: phpimage

解决方案


推荐阅读