ThinkPHP prompts callanundefinedfunctionexif_imagetype () When making text watermark _ php instance

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.