Skip to content

Instantly share code, notes, and snippets.

@lizhug
Created May 9, 2017 05:30
Show Gist options
  • Save lizhug/ec00dd0253d9677d1f6b95229e936aca to your computer and use it in GitHub Desktop.
Save lizhug/ec00dd0253d9677d1f6b95229e936aca to your computer and use it in GitHub Desktop.
php图片合并、添加文字
<?php
$path = "assets/img/qrcode_invite_template.jpeg";
$image = imagecreatefromjpeg($path);
$imageInfo = getimagesize($path);
//合成昵称
$textColor = imagecolorallocatealpha($image,255,0,0,50); //字体颜色
$textContent = "反倒是咖啡";
imagettftext($image, 14, 0, 253, 90, $textColor, "assets/fonts/dqht.ttf", $textContent);
//合成二维码图片
$imageQRCode = imagecreatefromjpeg("assets/img/showqrcode.jpeg");
$tmpQRCode =imagecreatetruecolor(140, 140);
imagecopyresampled($tmpQRCode, $imageQRCode, 0, 0, 0, 0, imagesx($tmpQRCode), imagesy($tmpQRCode), imagesx($imageQRCode), imagesy($imageQRCode));
imagecopymerge($image, $tmpQRCode, 160, 526, 0, 0, imagesx($tmpQRCode), imagesy($tmpQRCode), 100);
header('Content-type: ' . $imageInfo['mime']);
imagejpeg($image);
imagedestroy($image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment