本文实例讲述了ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法。分享给大家供大家参考。具体如下:
一、问题描述:
ThinkPHP做文字水印 ,今天做一个电子请帖,就把祝福语贴到图片上面,发现一直报错是取不到图片类型,比如gif,jpg等,并提示call an undefined function exif_imagetype()。
二、解决方法:
出现这个错误就是PHP.in 配置问题,打开即可:PHP_exif.dll 如果再不行就把extension=PHP_mbstring.dll,放到extension=PHP_exif.dll前边
注意:
extension=PHP_exif.dll 扩展要打开
类文件:wptext_class.PHP代码如下:
//添加文字的大小
public function GetFtSize($size)
{
$this->size = $size;
}
//文字旋转的角度
public function GetTtAngle($angle)
{
$this->angle = $angle;
}
//添加文字的位置
public function GetTtPosit()
{
$this->px = 10;
$this->py = imagesy($this->im) - 20;
}
//添加文字水印
public function AddWpText($pict)
{
$ext = exif_imagetype($pict);
switch ($ext) {
case 1:
$picext = "gif";
$this->im = imagecreatefromgif($pict);
break;
case 2:
$picext = "jpg";
$this->im = imagecreatefromjpeg($pict);
break;
case 3:
$picext = "png";
$this->im = imagecreatefrompng($pict);
break;
default:
$this->Errmsg("不支持的文件格式!");
break;
}
//$this->picext = $picext;
$this->GetTtPosit();
$im = $this->im;
$size = $this->size;
$angle= $this->angle;
$px = $this->px;
$py = $this->py;
$color= $this->color;
$font = $this->font;
$text = $this->text;
$color= imagecolorallocate($im,255,0);
imagettftext($im,$text);
switch ($picext) {
case "gif":
imagegif($im,$pict);
break;
case "jpg":
imagejpeg($im,$pict,100);
break;
case "png":
imagealphablending($im,false);
imagesavealpha($im,true);
imagepng($im,$pict);
break;
}
imagedestroy($im);
}
//错误信息提示
public function Errmsg($msg)
{
echo "";
}
//类结束
}
?>
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。