private
$waterImg_info
= '';
//水印图片信息
private
$str_w
= '';
//水印文字宽度
private
$str_h
= '';
//水印文字高度
private
$x
= '';
//水印 X 坐标
private
$y
= '';
//水印 y 坐标
function
__construct(
$img
) {
//析构函数
$this
->srcImg =
file_exists
(
$img
) ?
$img
:
die
('"'.
$img
.'" 源文件不存在!');
}
private
function
imginfo() {
//获取需要添加水印的图片的信息,并载入图片。
$this
->srcImg_info =
getimagesize
(
$this
->srcImg);
switch
(
$this
->srcImg_info[2]) {
case
3:
$this
->im = imagecreatefrompng(
$this
->srcImg);
break
1;
case
2:
$this
->im = imagecreatefromjpeg(
$this
->srcImg);
break
1;
case
1:
$this
->im = imagecreatefromgif(
$this
->srcImg);
break
1;
default
:
die
('原图片('.
$this
->srcImg.')格式不对,只支持 PNG、JPEG、GIF。');
}
}
private
function
waterimginfo() {
//获取水印图片的信息,并载入图片。
$this
->waterImg_info =
getimagesize
(
$this
->waterImg);
switch
(
$this
->waterImg_info[2]) {
case
3:
$this
->water_im = imagecreatefrompng(
$this
->waterImg);
break
1;
case
2:
$this
->water_im = imagecreatefromjpeg(
$this
->waterImg);
break
1;
case
1:
$this
->water_im = imagecreatefromgif(
$this
->waterImg);
break
1;
default
:
die
('水印图片('.
$this
->srcImg.')格式不对,只支持 PNG、JPEG、GIF。');
}
}
private
function
waterpos() {
//水印位置算法
switch
(
$this
->pos) {
case
0:
//随机位置