Home >Backend Development >PHP Tutorial >ThinkPHP prompts call an undefined function exif_imagetype() solution when making text watermark, _PHP tutorial

ThinkPHP prompts call an undefined function exif_imagetype() solution when making text watermark, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:381286browse

ThinkPHP prompts call an undefined function exif_imagetype() solution when making text watermarks,

The example in this article describes the solution to the problem that ThinkPHP prompts call an undefined function exif_imagetype() when making text watermarks. Share it with everyone for your reference. The details are as follows:

1. Problem description:

ThinkPHP makes text watermarks. Today I made an electronic invitation and pasted the blessing words on the picture. I found that it kept reporting errors and could not get the image type, such as gif, jpg, etc., and prompted call an undefined function exif_imagetype().

2. Solution:

This error is a php.in configuration problem, just open it: Open the extension extension=php_exif.dll. If it still doesn’t work, put extension=php_mbstring.dll in front of extension=php_exif.dll
Note: extension=php_exif.dll extension needs to be turned on
Class file: wptext_class.php code is as follows:

Copy code The code is as follows:
/*
PHP adds text watermark class V1.0
Author: Yu Tiedun
Email:
Modification date: 2010-03-07
Supported image formats: gif, jpg, png
The position of the watermark can be adjusted as needed
If you can modify it better, please send me a copy
*/
class WaterPrint
{
//Class start
Public $text, $color, $size, $font, $angle, $px, $py, $im;
//Text to add
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 text size
public function GetFtSize($size)
{
$this->size = $size;
}
//Angle of text rotation
public function GetTtAngle($angle)
{
$this->angle = $angle;
}
//Add text position
public function GetTtPosit()
{
$this->px = 10;
$this->py = imagesy($this->im) - 20;
}
//Add 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 "";
}
//End of class
}
?>

Calling page: index.php code is as follows:

Copy code The code is as follows:
header("Content-type: text/html; charset=gbk");
require("wptext_class.php");
$pict = "images/button2.png"; //Target image
//$text = "XP/Vista/Win7"; //Text to be added
$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, counterclockwise
$wptext = new WaterPrint();
$wptext->GetWpText($text);
$wptext->GetFtSize($size);
$wptext->GetFtType($font);
$wptext->GetTtAngle($angle);
$wptext->AddWpText($pict);
$wptext = null;
?>
View results

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/903483.htmlTechArticleThinkPHP prompts call an undefined function exif_imagetype() solution when making text watermarks. This article describes the example of ThinkPHP making text watermarks. When prompted call an undefined function exif_imag...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn