- 开发无止境 -
Data: 2013-12-23 18:03:54Form: JournalClick: 12
public function createImg($result, $string){
$backgroundPath = '背景图路径';
$img = imagecreatefromjpeg($backgroundPath); //背景图
//设置字体颜色
$black = imagecolorallocate($img, 0, 0, 0);
//字体大小
$size = 20;
if(strlen($string) > 24){
$size = 18;
}
//字体
$font = "assets/fonts/msyhbd.ttf";
//将ttf文字写到图片中
imagettftext($img, $size, 0, 108, 502, $black, $font, $string);
$filePathDir = '生成路径';
if (!is_dir($filePathDir)) {
mkdir($filePathDir, 0777, true);
}
$filePath = $filePathDir.time().rand(0,999).'.jpg';
imagejpeg($img,$filePath);
return $filePath;
}