This article mainly introduces the callanundefinedfunctionexif_imagetype () solution when ThinkPHP is used as a text watermark. It is a very practical technique in project development, for more information about ThinkPHP, see the following example: call an undefined function exif_imagetype. Share it with you for your reference. The details are as follows:
I. Problem description:
ThinkPHP makes a text watermark. Today, when I make an electronic invitation, I paste the greeting language on the image and find that the image type cannot be obtained because the error is always reported, such as gif and jpg, the system prompts call an undefined function exif_imagetype ().
Ii. solution:
This error occurs when php. in is configured. Open extended extension = php_exif.dll and put extension = php_mbstring.dll in the front of extension = php_exif.dll.
Note:Extension = php_exif.dll extension to open
Class file: wptext_class.php code is as follows:
The Code is as follows:
<? Php
/*
PHP add text watermark class V1.0
Author: Yu Tiedun
Email:
Modified on:
Supported image formats: gif, jpg, and png
Adjust the watermark position as needed
If the modification is better, please send me a copy.
*/
Class WaterPrint
{
// Starts the class
Public $ text, $ color, $ size, $ font, $ angle, $ px, $ py, $ im;
// Text to be added
Public function GetWpText ($ text)
{
$ This-> text = $ text;
}
// Add text color
Public function GetFtColor ($ color)
{
$ This-> color = $ color;
}
// Add text font
Public function GetFtType ($ font)
{
$ This-> font = $ font;
}
// Add the text size
Public function GetFtSize ($ size)
{
$ This-> size = $ size;
}
// Text Rotation Angle
Public function GetTtAngle ($ angle)
{
$ This-> angle = $ angle;
}
// Add text position
Public function GetTtPosit ()
{
$ This-> px = 10;
$ This-> py = imagesy ($ this-> im)-20;
}
// Add a 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"