合成推广二维码
$img_url = $this->getCode("{$userId}");
$name = ROOT_PATH."/public/code/" . $this->get_random();
$code_filename = \File::downloadImage($img_url, $name);
$head_url = Db::table('tp_wy_users')->where('id',$userId)->value('head_url');
if (empty($head_url)) {
$head_filename = ROOT_PATH.'public/static/baseimg/head.jpg';
}else{
$name = ROOT_PATH."/public/code/" . $this->get_random();
$this->download($head_url,$name.'.jpg');
$head_filename = $name.'.jpg132';
};
$imgs = array(
'base' => ROOT_PATH.'public/static/baseimg/base.jpg',
'code' => $code_filename,
'head' => $head_filename,
);
list($max_width, $max_height) = getimagesize($imgs['base']);
$dests = imagecreatetruecolor($max_width, $max_height);
$dst_im = imagecreatefromjpeg($imgs['base']);
imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height);
imagedestroy($dst_im);
$src_im = imagecreatefromjpeg($imgs['code']);
$src_info = getimagesize($imgs['code']);
imagecopy($dests,$src_im,110,480,0,0,$src_info[0],$src_info[1]);
imagedestroy($src_im);
$head_type = getimagesize($imgs['head']);
switch ($head_type['mime']) {
case "image/jpeg":
$src_im2 = imagecreatefromjpeg($imgs['head']);
break;
case "image/png":
$src_im2 = imagecreatefrompng($imgs['head']);
break;
default:
$src_im2 = imagecreatefromjpeg($imgs['head']);
}
$src_info2 = getimagesize($imgs['head']);
imagecopy($dests,$src_im2,20,40,0,0,$src_info2[0],$src_info2[1]);
imagedestroy($src_im2);
$username = Db::table('tp_wy_users')->where('id',$userId)->value('xm');
$name = "会员:".$username;
$red = imagecolorallocate($dests, 255, 0, 0);
ImageTTFText($dests, 20, 0, 160, 120, $red, ROOT_PATH."application/simkai.ttf", $name);
$last_filename = ROOT_PATH."/public/code/" . $this->get_random().'.jpg';
imagejpeg($dests,$last_filename);
$wechat = new \app\common\weixin\Wechat($this->optionAuth);
$arryimg = [
"media"=>'@'.$last_filename,
];
$imgurl = $wechat->uploadMedia($arryimg,'image');
$outcodeid = $imgurl["media_id"];
Db::table('tp_wy_users')->where('id',$userId)->update(['outcodeid'=>$outcodeid]);