thinkphp a undefined function exif_imagetype () solution _php instance when making a text watermark

Source: Internet
Author: User
In this paper, we describe the solution of undefined function exif_imagetype (), which is prompted by thinkphp to make a text watermark. Share to everyone for your reference. Specific as follows:

First, the problem description:

thinkphp do a text watermark, today to do an electronic invitation, the blessing of the language affixed to the picture above, found that the error is not to take the picture type, such as gif,jpg, and prompted call a undefined function exif_imagetype ().

Second, the solution:

This error is php.in configuration problem, open can: open extension Extension=php_exif.dll if not again, put Extension=php_mbstring.dll, put the EXTENSION=PHP_ Exif.dll Front
Note: extension=php_exif.dll extension to open
class file: The wptext_class.php code is as follows:

Copy CodeThe code is as follows: <?php
/*
PHP Add text watermark class V1.0
Author: Yu Tiedun
Mailbox:
Date Modified: 2010-03-07
Supported image formats: GIF, JPG, png
The location of the watermark adjusts itself as needed
If you can change it better, please send me a copy.
*/
Class Waterprint
{
Class start
Public $text, $color, $size, $font, $angle, $px, $py, $im;
The text to add
Public Function Getwptext ($text)
{
$this->text = $text;
}
Add color to Text
Public Function Getftcolor ($color)
{
$this->color = $color;
}
Add font to Text
Public Function Getfttype ($font)
{
$this->font = $font;
}

Add the size of text
Public Function getftsize ($size)
{
$this->size = $size;
}
The angle of the text rotation
Public Function Getttangle ($angle)
{
$this->angle = $angle;
}
Where to add text
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 hint
Public function errmsg ($msg)
{
echo "";
}
Class End
}
?>

Call page: The index.php code is as follows:

Copy the Code code as follows: <?php
Header ("content-type:text/html; CHARSET=GBK ");
Require ("wptext_class.php");
$pict = "Images/button2.png"; Target picture
$text = "xp/vista/win7"; The text to add
$text = "text watermark test";
$text = Iconv ("gb2312", "Utf-8", $text); Prevent Chinese garbled characters
$size = 20; Text Size
$font = "C:/windows/fonts/arial.ttf"; Font
$angle = 0; Rotation angle, counter-clockwise
$wptext = new Waterprint ();
$wptext->getwptext ($text);
$wptext->getftsize ($size);
$wptext->getfttype ($font);
$wptext->getttangle ($angle);
$wptext->addwptext ($pict);
$wptext = null;
?>
View Results

It is hoped that this article will be helpful to everyone's thinkphp framework design.

  • 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.