Created
May 9, 2017 05:30
-
-
Save lizhug/ec00dd0253d9677d1f6b95229e936aca to your computer and use it in GitHub Desktop.
php图片合并、添加文字
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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