当前位置:首页 > CMS教程 > Thinkphp > 列表

ThinkPHP做文字水印时提示call an undefined function exif_imagetype()解决方法

发布:smiling 来源: PHP粉丝网  添加日期:2021-04-19 19:30:35 浏览: 评论:0 

这篇文章主要介绍了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代码如下:

  1. <?php 
  2. /* 
  3. PHP添加文字水印类 V1.0 
  4. 作者:Yu Tiedun 
  5. 邮箱: 
  6. 修改日期:2010-03-07 
  7. 支持图片格式:gif, jpg, png 
  8. 水印的位置自己根据需要调整 
  9. 如能修改得更好,请发一份给我 
  10. */ 
  11. class WaterPrint 
  12. { 
  13. //类开始 
  14.     public $text, $color, $size, $font, $angle, $px, $py, $im; 
  15. //要添加的文字 
  16. public function GetWpText($text) 
  17. { 
  18.    $this->text = $text; 
  19. } 
  20. //添加文字的颜色 
  21. public function GetFtColor($color) 
  22. { 
  23.    $this->color = $color; 
  24. } 
  25. //添加文字的字体 
  26. public function GetFtType($font) 
  27. { 
  28.    $this->font = $font; 
  29. } 
  30.  
  31. //添加文字的大小 
  32. public function GetFtSize($size) 
  33. { 
  34.    $this->size = $size; 
  35. } 
  36. //文字旋转的角度 
  37. public function GetTtAngle($angle) 
  38. { 
  39.    $this->angle = $angle; 
  40. } 
  41. //添加文字的位置 
  42. public function GetTtPosit() 
  43. { 
  44.    $this->px = 10; 
  45.    $this->py = imagesy($this->im) - 20; 
  46. } 
  47. //添加文字水印 
  48. public function AddWpText($pict) 
  49. { 
  50.    $ext = exif_imagetype($pict); 
  51.     switch ($ext) { 
  52.    case 1: 
  53.    $picext = "gif"; 
  54.     $this->im = imagecreatefromgif($pict); 
  55.     break; 
  56.    case 2: 
  57.    $picext = "jpg"; 
  58.     $this->im = imagecreatefromjpeg($pict); 
  59.     break; 
  60.    case 3: 
  61.    $picext = "png"; 
  62.     $this->im = imagecreatefrompng($pict); 
  63.     break; 
  64.    default: 
  65.    $this->Errmsg("不支持的文件格式!"); 
  66.     break; 
  67.    } 
  68.    //$this->picext = $picext; 
  69.    $this->GetTtPosit(); 
  70.    $im   = $this->im; 
  71.    $size = $this->size; 
  72.    $angle= $this->angle; 
  73.    $px   = $this->px; 
  74.    $py   = $this->py; 
  75.    $color= $this->color; 
  76.    $font = $this->font; 
  77.    $text = $this->text; 
  78.    $color= imagecolorallocate($im, 255, 0, 0); 
  79.    imagettftext($im, $size, $angle, $px, $py, $color, $font, $text); 
  80.    switch ($picext) { 
  81.    case "gif": 
  82.    imagegif($im, $pict); 
  83.     break; 
  84.    case "jpg": 
  85.    imagejpeg($im, $pict, 100); 
  86.     break; 
  87.    case "png": 
  88.       imagealphablending($im, false); 
  89.         imagesavealpha($im, true); 
  90.        imagepng($im, $pict); 
  91.     break; 
  92.    } 
  93.    imagedestroy($im); 
  94. }//www.phpfensi.com 
  95. //错误信息提示 
  96. public function Errmsg($msg) 
  97. { 
  98.     echo "<script language='javascript'>alert('".$msg."');</script>"; 
  99. } 
  100. //类结束 
  101. } 
  102. ?> 

调用页面:index.php代码如下:

  1. <?php 
  2. header("Content-type: text/html; charset=gbk"); 
  3. require("wptext_class.php"); 
  4. $pict = "images/button2.png"; //目标图片 
  5. //$text = "XP/Vista/Win7"; //要添加的文字 
  6. $text = "文字水印测试"; 
  7. $text = iconv("gb2312","utf-8",$text); //防止中文乱码 
  8. $size = 20; //文字大小 
  9. $font = "c:/windows/fonts/arial.ttf"; //字体 
  10. $angle = 0; //旋转角度,逆时针 
  11. $wptext = new WaterPrint(); 
  12. $wptext->GetWpText($text); 
  13. $wptext->GetFtSize($size); 
  14. $wptext->GetFtType($font); 
  15. $wptext->GetTtAngle($angle); 
  16. $wptext->AddWpText($pict); 
  17. $wptext = null; 
  18. ?> 
  19. <a href="images/button2.png" target="_blank">查看结果</a> 

希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Tags: undefined function exif_imagetype

分享到: