//调用 public function cp(){ $this->_createPic(285,141,18,30,75,'block','电动自行车一辆3500km/h及安全帽一个');}/*** @param int $imgW 画布的宽度* @param int $imgH 画布的高度* @param int $imgTestSize 字体的尺寸为像素尺寸(GD1)或点(磅)尺寸(GD2)。* @param int $imgTextX 由 x,y 所表示的坐标定义了第一个字符的基本点* @param int $imgTestY* @param string $imgBackgroundColor 画布的背景颜色 分两种 :block 表示黑色 其它表示为白色* @param string $text 要显示的文字内容*/private function _createPic($imgW=285,$imgH=141,$imgTestSize=20,$imgTextX=50,$imgTestY=75,$imgBackgroundColor='block',$text= "我叫苏三"){$font =WEB_ROOT .'Lib/ORG/simsun.ttf';$font=str_replace("\\", "/",$font);$im = imagecreate($imgW, $imgH);if($imgBackgroundColor==='block'){$bg = imagecolorallocate($im, 0, 0, 0); //设置画布的背景为白色$black = imagecolorallocate($im,255, 255, 255); //设置一个颜色变量为黑色}else{$bg = imagecolorallocate($im,255, 255, 255); //设置画布的背景为白色$black = imagecolorallocate($im,0, 0, 0); //设置一个颜色变量为黑色}//$textLen=_strlen($text);$textLen=abslength($text);//判断是否大于两行if($textLen>10){$arr[0]=mb_substr($text, 0, 10, 'utf-8');//大于两行,进行省略if($textLen>=20){$arr[1]=mb_substr($text, 10, 9, 'utf-8').'...';}else{$arr[1]=mb_substr($text, 10, 10, 'utf-8');}imagettftext($im, $imgTestSize, 0, $imgTextX, $imgTestY-15, $black, $font, $arr[0]); //输出一个灰色的字符串作为阴影imagettftext($im, $imgTestSize, 0, $imgTextX, $imgTestY+15, $black, $font, $arr[1]); //输出一个灰色的字符串作为阴影}else{if($textLen>=1 && $textLen<8){$imgTextX+=(10-$textLen)*10;//一个字平均占10个像素}imagettftext($im, $imgTestSize, 0, $imgTextX, $imgTestY, $black, $font, $text); //输出一个灰色的字符串作为阴影}header('Content-type:image/png');imagepng($im);}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!