php - 生成二维码并合并到编辑后的 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);
解决方案
推荐阅读
- javascript - 在 React Native 中使用 Redux 注销时出现错误导航器
- mips - 在 MIPS 中使用递归搜索二叉树
- php - 使用 Ionic httpClient POST 到 PHP API 不发送任何数据
- angular - 我可以为 angular/typescript 中的导入库提供别名吗?
- intellij-idea - 如何在 IntelliJ 项目中添加新包?
- speech-recognition - 不能识别除英语以外的其他语言的句子
- android - 在布局 xml 中定义 Android 标签不起作用
- c - 如何在cmake窗口中添加资源
- amazon-web-services - 通过网关 websocket 调用长时间运行的 Lambda 的最简单方法是什么?
- c++ - 尝试初始化静态方法时出现错误“方法在此上下文中是私有的”