The example of this article tells the thinkphp undefined function exif_imagetype () solution for text watermark. Share to everyone for your reference. Specifically as follows:
First, the problem description:
thinkphp do a text watermark, today to do an electronic invitation, the blessing of the picture above, found that the error is not to get 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 to: open extension Extension=php_exif.dll If no longer extension=php_mbstring.dll, put the EXTENSION=PHP_ Exif.dll Front
Note:extension=php_exif.dll extension to open
class file: wptext_class.php code as follows:
Copy Code code as follows:
<?php
/*
PHP Add text watermark class V1.0
Author: Yu Tiedun
Mailbox:
Modification Date: 2010-03-07
Support picture format: GIF, JPG, png
The location of the watermark adjusts itself according to need
If you can change it better, please send me a copy.
*/
Class Waterprint
{
Class starts
Public $text, $color, $size, $font, $angle, $px, $py, $im;
The text you want 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 prompt
Public function errmsg ($msg)
{
echo "<script language= ' JavaScript ' >alert ('. $msg."); </script> ";
}
Class End
}
?>
Call page: index.php code as follows:
Copy 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 you want to add
$text = "text watermark test";
$text = Iconv ("gb2312", "Utf-8", $text); Prevent Chinese garbled
$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;
?>
<a href= "images/button2.png" target= "_blank" > View results </a>
I hope this article will be helpful to everyone's thinkphp framework program design.