ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法
程序员文章站
2022-05-31 12:36:06
本文实例讲述了thinkphp做文字水印时提示call an undefined function exif_imagetype()解决方法。分享给大家供大家参考。具体如下...
本文实例讲述了thinkphp做文字水印时提示call an undefined function exif_imagetype()解决方法。分享给大家供大家参考。具体如下:
一、问题描述:
thinkphp做文字水印 ,今天做一个电子请帖,就把祝福语贴到图片上面,发现一直报错是取不到图片类型,比如gif,jpg等,并提示call an undefined function exif_imagetype()。
二、解决方法:
出现这个错误就是php.in 配置问题,打开即可:打开扩展 extension=php_exif.dll 如果再不行就把extension=php_mbstring.dll ,放到extension=php_exif.dll前边
注意:extension=php_exif.dll 扩展要打开
类文件:wptext_class.php代码如下:
复制代码 代码如下:
<?php
/*
php添加文字水印类 v1.0
作者:yu tiedun
邮箱:
修改日期:2010-03-07
支持图片格式:gif, jpg, png
水印的位置自己根据需要调整
如能修改得更好,请发一份给我
*/
class waterprint
{
//类开始
public $text, $color, $size, $font, $angle, $px, $py, $im;
//要添加的文字
public function getwptext($text)
{
$this->text = $text;
}
//添加文字的颜色
public function getftcolor($color)
{
$this->color = $color;
}
//添加文字的字体
public function getfttype($font)
{
$this->font = $font;
}
//添加文字的大小
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, 0);
imagettftext($im, $size, $angle, $px, $py, $color, $font, $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 "<script language='javascript'>alert('".$msg."');</script>";
}
//类结束
}
?>
/*
php添加文字水印类 v1.0
作者:yu tiedun
邮箱:
修改日期:2010-03-07
支持图片格式:gif, jpg, png
水印的位置自己根据需要调整
如能修改得更好,请发一份给我
*/
class waterprint
{
//类开始
public $text, $color, $size, $font, $angle, $px, $py, $im;
//要添加的文字
public function getwptext($text)
{
$this->text = $text;
}
//添加文字的颜色
public function getftcolor($color)
{
$this->color = $color;
}
//添加文字的字体
public function getfttype($font)
{
$this->font = $font;
}
//添加文字的大小
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, 0);
imagettftext($im, $size, $angle, $px, $py, $color, $font, $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 "<script language='javascript'>alert('".$msg."');</script>";
}
//类结束
}
?>
调用页面:index.php代码如下:
复制代码 代码如下:
<?php
header("content-type: text/html; charset=gbk");
require("wptext_class.php");
$pict = "images/button2.png"; //目标图片
//$text = "xp/vista/win7"; //要添加的文字
$text = "文字水印测试";
$text = iconv("gb2312","utf-8",$text); //防止中文乱码
$size = 20; //文字大小
$font = "c:/windows/fonts/arial.ttf"; //字体
$angle = 0; //旋转角度,逆时针
$wptext = new waterprint();
$wptext->getwptext($text);
$wptext->getftsize($size);
$wptext->getfttype($font);
$wptext->getttangle($angle);
$wptext->addwptext($pict);
$wptext = null;
?>
<a href="images/button2.png" target="_blank">查看结果</a>
header("content-type: text/html; charset=gbk");
require("wptext_class.php");
$pict = "images/button2.png"; //目标图片
//$text = "xp/vista/win7"; //要添加的文字
$text = "文字水印测试";
$text = iconv("gb2312","utf-8",$text); //防止中文乱码
$size = 20; //文字大小
$font = "c:/windows/fonts/arial.ttf"; //字体
$angle = 0; //旋转角度,逆时针
$wptext = new waterprint();
$wptext->getwptext($text);
$wptext->getftsize($size);
$wptext->getfttype($font);
$wptext->getttangle($angle);
$wptext->addwptext($pict);
$wptext = null;
?>
<a href="images/button2.png" target="_blank">查看结果</a>
希望本文所述对大家的thinkphp框架程序设计有所帮助。
上一篇: apk 反编译 教程 (不支持混淆,Android)
下一篇: 为这样的老师顶一个
推荐阅读
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解_PHP
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法,_PHP教程
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法,
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解
-
ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解