When ThinkPHP is used for text watermark, the system prompts call an undefined function exif_imagetype () solution,
This example describes how to call an undefined function exif_imagetype () When ThinkPHP is used as a text watermark. 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:
Copy codeThe 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 "<script language = 'javascript '> alert ('". $ msg. "'); </script> ";
}
// End the class
}
?>
Call page: The index. php code is as follows:
Copy codeThe Code is as follows: <? Php
Header ("Content-type: text/html; charset = gbk ");
Require ("wptext_class.php ");
$ Pict = "images/button2.png"; // target image
// $ Text = "XP/Vista/Win7"; // The text to be added
$ Text = "text watermark test ";
$ Text = iconv ("gb2312", "UTF-8", $ text); // prevents Chinese garbled characters
$ Size = 20; // text size
$ Font = "c:/windows/fonts/arial. ttf"; // font
$ Angle = 0; // rotation angle, 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 results </a>
I hope this article will help you with ThinkPHP framework programming.