php绘图 并在上面添加LOGO和文字
public function tu(){
header("content-type:image/jpeg;charset=GBK");//表明请求页面的内容是jpeg格式的图像 即当前页面会以图片的新式展示 去掉这行 就可以显示正常的网页了
$logo = "logo.jpg";
$image = imagecreatefrompng ("123.png");//打开一张jpg图片
$b1 = imagecolorallocate ( $image , 3,171,189);//为该图片定义一个颜色
$b2 = imagecolorallocate ( $image , 16,16,16);//为该图片定义一个颜色
$b3 = imagecolorallocate ( $image , 166,166,166);//为该图片定义一个颜色
$font = "./Public/assetsshop/fonts/arialuni.ttf";//已有的子图路径
//list( $width , $height , $type , $attr ) = getimagesize ("123.jpg" );//获得当前图片的宽、高
//打印出坐标 方便布局
// for ($i = 0;$i < $width;$i += 25)
// {
// imagettftext ( $image , 5 , 0 , $i , 5 , $black , $font , $i );
// }
// for ($i = 0;$i < $height;$i += 25)
// {
// imagettftext ( $image , 5 , 0 , 0 , $i , $black , $font , $i );
// }
//使用指定的字体文件绘制文字
//参数2:字体大小
//参数3:字体倾斜的角度
//参数4、5:文字的x、y坐标
//参数6:文字的颜色
//参数7:字体文件
//参数8:绘制的文字
imagettftext ( $image , 16 , 0 , 15 , 40 , $b1 , $font , "¥20-30K" );//往图片上添加文字
imagettftext ( $image , 13 , 0 , 110 , 40 , $b3 , $font , "上海3-5年本科" );//往图片上添加文字
imagettftext ( $image , 14 , 0 , 80 , 240 , $b2 , $font , "刘女士" );//往图片上添加文字
imagettftext ( $image , 13 , 0 , 80 , 260 , $b3 , $font , "甜橙金融·HRBP" );//往图片上添加文字
imagettftext ( $image , 14 , 0 , 265 , 240 , $b1 , $font , "本周活跃" );//往图片上添加文字
// imagettftext ( $image , 14 , 0 , 115 , 215 , $black , $font , "¥20-30K" );//往图片上添加文字
// $file_name="456.jpg";//设置图片文件名
$file_name="456.png";//设置图片文件名
$file_names="4567.png";//设置图片文件名
$file_name=iconv("utf-8","gb2312",$file_name); //解决中文乱码问题
// imagejpeg($image,$file_name);//如果只要第一个参数就是输出到页面 此时就必须使用 header说明页面内容为图片 ,如果有第二个参数就是 输出到文件, 此时页面就不会有图片输出,就可以去掉header头
// imagepng($image,$file_name);
if ($logo !== FALSE) {
imagepng($image,$file_name);
$QR = $file_name;
$QR = imagecreatefromstring(file_get_contents($QR));
$logo = imagecreatefromstring(file_get_contents($logo));
$QR_width = imagesx($QR);//背景图片宽度
$QR_height = imagesy($QR);//背景图片高度
$logo_width = imagesx($logo);//logo图片宽度
$logo_height = imagesy($logo);//logo图片高度
$logo_qr_width = $QR_width / 7;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$from_width = ($QR_width - $logo_qr_width) / 2;
//重新组合图片并调整大小
//背景图片,logo图片,logo图片的X坐标,logo图片的Y坐标,logo图片的X坐标载入位置,LOGO图片的Y坐标载入位置,logo图片的宽,logo图片的高,背景图片的宽,背景图片的高
// imagecopyresampled($QR, $logo, $from_width, $from_width, 10, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
imagecopyresampled($QR, $logo, 15, 225, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
imagepng($QR);
imagedestroy($QR);
}else{
imagepng($image);
imagedestroy($img);
}
}