php合成海报

//参数1 是因为需要微信用户头像,所以穿了对象过去

//参数2 文件存储地址

//参数3 二维码图片地址

function img2img_hb($wxUserInfo,$imgdir,$qrurl){
global $cssurl;//全局静态文件地址
$bigImg = imagecreatefromstring(file_get_contents($cssurl.'/hb/mb/muban.png'));
$font = $cssurl.'/hb/font/msyh.ttc';

$black = imagecolorallocate($bigImg, 102, 102, 102);

imagefttext($bigImg, 16, 0, 164, 900, $black, $font, $wxUserInfo->nickname);//用户名
$url = $wxUserInfo->headimgurl;//生成圆角

$txImg = radius_img($url,0);

$tx_width = imagesx($txImg);
$tx_height = imagesy($txImg);
imagecopyresized($bigImg, $txImg, 29, 826, 0, 0, 112,112,$tx_width,$tx_height);

$curl = curl_init($qrurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$qrdata = curl_exec($curl);
curl_close($curl);

$qCodeImg = imagecreatefromstring($qrdata);
imagecopyresized($bigImg, $qCodeImg, 425, 761, 0, 0, 195,195,300,300);
//header('Content-Type: image/jpeg');
imagepng($bigImg,$imgdir);
@chmod($imgdir,0777);
imagedestroy($bigImg);
return $imgdir;
//imagepng($bigImg);
//exit;
}

扫描二维码关注公众号,回复: 7320408 查看本文章

/* *
* 图片圆角生成 这是复制的其他人的,哈哈哈
**/
function radius_img($imgpath = './t.png', $radius = 15) {
$ch = curl_init($imgpath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$txImg = imagecreatefromstring($data);//头像处理

$w = imagesx($txImg);
$h = imagesy($txImg);
$radius = $radius == 0 ? (min($w, $h) / 2) : $radius;
$img = imagecreatetruecolor($w, $h);
//这一句一定要有
imagesavealpha($img, true);
//拾取一个完全透明的颜色,最后一个参数127为全透明
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $bg);
$r = $radius; //圆 角半径
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($txImg, $x, $y);
if (($x >= $radius && $x <= ($w - $radius)) || ($y >= $radius && $y <= ($h - $radius))) {
//不在四角的范围内,直接画
imagesetpixel($img, $x, $y, $rgbColor);
} else {
//在四角的范围内选择画
//上左
$y_x = $r; //圆心X坐标
$y_y = $r; //圆心Y坐标
if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
//上右
$y_x = $w - $r; //圆心X坐标
$y_y = $r; //圆心Y坐标
if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
//下左
$y_x = $r; //圆心X坐标
$y_y = $h - $r; //圆心Y坐标
if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
//下右
$y_x = $w - $r; //圆心X坐标
$y_y = $h - $r; //圆心Y坐标
if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
}
}
}
return $img;
}

猜你喜欢

转载自www.cnblogs.com/hubudong/p/11551257.html