/*
PHP添加文字水印类 V1.0
作 者:Yu Tiedun
邮 箱:
修改日期:2010-03-07
支持图片格式:gif, jpg, png
水印的位置自己根据需要调整
如能修改得更好,请发一份给我
*/
class WaterPrint
{
//类开始
public $text, $color, $size, $font, $angle, $px, $py, $im;
//要添加的文字
public function GetWpText($text)
{
$this->text = $text;
}
//添加文字的颜色
public function GetFtColor($color)
{
$this->color = $color;
}
//添加文字的字体
public function GetFtType($font)
{
$this->font = $font;
}
//添加文字的大小
public function GetFtSize($size)
{
$this->size = $size;
}
//文字旋转的角度
public function GetTtAngle($angle)
{
$this->angle = $angle;
}
//添加文字的位置
public function GetTtPosit()
{
$this->px = 10;
$this->py = imagesy($this->im) - 20;
}
//添加文字水印
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("不支持的文件格式!");
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);
}
//错误信息提示
public function Errmsg($msg)
{
echo "";
}
//类结束
}
?>
|