<?php
//指定图片路径

$src = 'j.png';
// var_dump(file_exists('j.png'));exit;
//获取图片信息

$info = getimagesize($src);

//获取图片扩展名

$type = image_type_to_extension($info[2],false);

//动态的把图片导入内存中

$fun = "imagecreatefrom{$type}";

$image = $fun('j.png');

//指定字体颜色

$col = imagecolorallocatealpha($image,0,0,0,50);
$kefd_color = imagecolorallocate($image, 255, 255, 255);

//指定字体内容

$content_str = '圣路易斯华盛顿大学辅导介绍';


//计算字符串长度
$num = strlen($content_str);
//判断文字是否需要换行
$shang = bcdiv($num,15);
$begin=0;
for($i=0; $i<=$shang; $i++){
if(empty($begin)){
$content = mb_strimwidth($content_str, 0, 15);
$begin += mb_strlen($content);
} else{
$content = mb_strimwidth($content_str, $begin, 15);
$begin += mb_strlen($content);
}
//给图片添加文字
$x=10;
$y=50+20*$i;
imagettftext($image,15,0,$x,$y,$col,"c:/windows/fonts/simhei.ttf",$content);
}

$kefd = '课业辅导';

//给图片添加文字
imagettftext($image,15,0,10,120,$kefd_color,"c:/windows/fonts/simhei.ttf",$kefd);
//指定输入类型

header('Content-type:'.$info['mime']);

//动态的输出图片到浏览器中

$func = "image{$type}";

$func($image);

//销毁图片

imagepng($image, 'image1.png'); //输出到目标文件

imagedestroy($image); //销毁内存数据流