这个是把文字和两张图片加载在背景图上面的
public function tu(){
header("content-type:image/jpeg;charset=GBK");
$logos = "123456.jpg";
$img = $this->yuan_img($logos);
imagepng($img,'666.png');
imagedestroy($img);
$logo = '666.png';
$code = "http://ezhao.bonnidee.cn/1.png";
$image = imagecreatefrompng ("bg.png");
$b1 = imagecolorallocate ( $image , 3,171,189);
$b2 = imagecolorallocate ( $image , 16,16,16);
$b3 = imagecolorallocate ( $image , 166,166,166);
$font = "./Public/assetsshop/fonts/arialuni.ttf";
imagettftext ( $image , 30 , 0 , 270 , 190 , $b2 , $font , "王胖子" );
imagettftext ( $image , 22 , 0 , 269 , 263 , $b2 , $font , "上海邦伲德·产品经理" );
imagettftext ( $image , 22 , 0 , 99 , 434 , $b2 , $font , "正在招聘" );
imagettftext ( $image , 22 , 0 , 100 , 912 , $b2 , $font , "邦伲德 期待你的加入" );
imagettftext ( $image , 40 , 0 , 99 , 525 , $b2 , $font , "产品经理" );
imagettftext ( $image , 45 , 0 , 100 , 635 , $b1 , $font , "20K-30K" );
imagettftext ( $image , 22 , 0 , 99 , 731 , $b2 , $font , "上海·普陀区|3-5年|本科" );
imagettftext ( $image , 22 , 0 , 99 , 974 , $b2 , $font , "2020/05/21" );
$file_name="456.png";
$file_name=iconv("utf-8","gb2312",$file_name);
imagepng($image,$file_name);
if ($logo !== FALSE) {
$QR = imagecreatefromstring(file_get_contents($file_name));
$logo = imagecreatefromstring(file_get_contents($logo));
$code = imagecreatefromstring(file_get_contents($code));
$QR_width = imagesx($QR);
$QR_height = imagesy($QR);
$logo_width = imagesx($logo);
$logo_height = imagesy($logo);
$logo_qr_width = $QR_width / 6;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$code_width = imagesx($code);
$code_height = imagesy($code);
$logo_qr_widths = $QR_width / 5;
$scales = $code_width/$logo_qr_widths;
$code_qr_height = $code_height/$scales;
imagecopyresampled($QR, $code, 550, 1405, 0, 0, $logo_qr_widths,$code_qr_height, $code_width, $code_height);
imagecopyresampled($QR, $logo, 110, 155, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
imagepng($QR);
}
imagedestroy($image);
exit;
}
这个是把图片处理成圆形的
public function yuan_img($imgpath) {
$ext = pathinfo($imgpath);
$src_img = null;
switch ($ext['extension']) {
case 'jpg':
$src_img = imagecreatefromjpeg($imgpath);
break;
case 'png':
$src_img = imagecreatefrompng($imgpath);
break;
}
$wh = getimagesize($imgpath);
$w = $wh[0];
$h = $wh[1];
$w = min($w, $h);
$h = $w;
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $bg);
$r = $w / 2;
$y_x = $r;
$y_y = $r;
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($src_img, $x, $y);
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
}
}
return $img;
}