Prompt call an undefined function exif_imagetype of solution when ThinkPHP does text watermarking
- 2021-07-22 09:24:14
- OfStack
In this paper, an example is given to describe the solution of prompting call an undefined function exif_imagetype () when ThinkPHP makes text watermarking. Share it for your reference. The details are as follows:
1. Problem description:
ThinkPHP is a text watermark. Today, when I make an electronic invitation, I post a greeting on the picture. I find that I can't get the picture type when I report an error directly, such as gif, jpg, etc., and prompt call an undefined function exif_imagetype ().
2. Solution:
This error is the configuration problem of php. in. Just open it: open the extension extension=php_exif. dll. If it doesn't work again, put extension=php_mbstring.dll before extension=php_exif. dll
Note: extension=php_exif. dll extension to open
Class file: The code for wptext_class. php is as follows:
<?php
/*
PHP Add a text watermark class V1.0
By: Yu Tiedun
Mailbox:
Date of modification: 2010-03-07
Supports picture formats: gif, jpg, png
The position of the watermark can be adjusted as needed
If it can be modified better, , Please send 1 Give me your share
*/
class WaterPrint
{
// Class start
public $text, $color, $size, $font, $angle, $px, $py, $im;
// Text to add
public function GetWpText($text)
{
$this->text = $text;
}
// Add the color of the text
public function GetFtColor($color)
{
$this->color = $color;
}
// Add the font of the text
public function GetFtType($font)
{
$this->font = $font;
}
// Add the size of the text
public function GetFtSize($size)
{
$this->size = $size;
}
// Angle of rotation of text
public function GetTtAngle($angle)
{
$this->angle = $angle;
}
// Where to add text
public function GetTtPosit()
{
$this->px = 10;
$this->py = imagesy($this->im) - 20;
}
// Add text watermark
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(" Unsupported file format! ");
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);
}
// Error message prompt
public function Errmsg($msg)
{
echo "<script language='javascript'>alert('".$msg."');</script>";
}
// Class end
}
?>
Call page: index. php code is as follows:
<?php
header("Content-type: text/html; charset=gbk");
require("wptext_class.php");
$pict = "images/button2.png"; // Target picture
//$text = "XP/Vista/Win7"; // Text to add
$text = " Text watermarking test ";
$text = iconv("gb2312","utf-8",$text); // Prevent Chinese garbled codes
$size = 20; // Text size
$font = "c:/windows/fonts/arial.ttf"; // Font
$angle = 0; // Angle of rotation , Counterclockwise
$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"> View the results </a>
I hope this article is helpful to everyone's ThinkPHP framework programming.