Thinkphp makes a text watermark and solves call an undefined function exif_imagetype ()

Source: Internet
Author: User

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, today, I wrote a watermark class and solved the call an undefined function exif_imagetype (). This error is php. in configuration problem. Open extended extension = php_exif.dll and put extension = php_mbstring.dll in front of extension = php_exif.dll.

Note: extension = php_exif.dll extension must be enabled.

Class File: wptext_class.php

The code is as follows: Copy code

<? Php
/*
PHP add text watermark class V1.0
Author: Yu Tiedun
Mail box:
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: index. php

The code is as follows: Copy code

<? 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>

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.