function water($bigPath,$pos=5){
$rootPath = dirname(dirname(__FILE__));
$bigPath = $rootPath.$bigPath;
$smallPath=$rootPath .'/images/logo.png';
$bigImgInfo= getimagesize($bigPath);
$smallImgInfo=getimagesize($smallPath);
switch ($bigImgInfo[2]){
case 1:
$bigImg= imagecreatefromgif($bigPath);
break;
case 2:
$bigImg= imagecreatefromjpeg($bigPath);
break;
case 3:
$bigImg= imagecreatefrompng($bigPath);
break;
}
switch($smallImgInfo[2]){
case 1:
$smallImg= imagecreatefromgif($smallPath);
break;
case 2:
$smallImg= imagecreatefromjpeg($smallPath);
break;
case 3:
$smallImg= imagecreatefrompng($smallPath);
break;
}
switch ($pos) {
case 1://左上角
imagecopy($bigImg, $smallImg, 0, 0, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //左上角
break;
case 2://右上角
imagecopy($bigImg, $smallImg, $bigImgInfo[0] - $smallImgInfo[0], 0, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //右上角=大图宽-小图宽 , 0
break;
case 3://右下角
imagecopy($bigImg, $smallImg, $bigImgInfo[0] - $smallImgInfo[0], $bigImgInfo[1] - $smallImgInfo[1], 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //右下角=大图宽-小图宽 , 大图高-小图高
break;
case 4://左下角
imagecopy($bigImg, $smallImg, 0, $bigImgInfo[1] - $smallImgInfo[1], 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //左下角=0 , 大图高-小图高
break;
case 5://居中
imagecopy($bigImg, $smallImg, ($bigImgInfo[0] - $smallImgInfo[0]) / 2, ($bigImgInfo[1] - $smallImgInfo[1]) / 2, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //居中=(大图宽-小图宽)/2 , (大图高-小图高)/2
break;
}
$newName = md5(uniqid()) . '.png';//已添加的水印图片新
$savePath = $rootPath . '/upload/water/';//已添加的水印图片保存目录
if (!is_dir($savePath)) {
if (!mkdir($savePath, 0777, true)) {
$_SESSION['fileerror']= 12;
header('location:../after_end/info.php');
exit();
}
}
$r =imagepng($bigImg, $savePath.$newName); //把已添加水印的图片保存到磁盘中
imagedestroy($bigImg);
imagedestroy($smallImg);
if ($r) {
return '/upload/water/'.$newName;//前端绝对路径
} else {
$_SESSION['fileerror']= 12;
header('location:../after_end/info.php');
exit();
}
}
$rootPath = dirname(dirname(__FILE__));
$bigPath = $rootPath.$bigPath;
$smallPath=$rootPath .'/images/logo.png';
$bigImgInfo= getimagesize($bigPath);
$smallImgInfo=getimagesize($smallPath);
switch ($bigImgInfo[2]){
case 1:
$bigImg= imagecreatefromgif($bigPath);
break;
case 2:
$bigImg= imagecreatefromjpeg($bigPath);
break;
case 3:
$bigImg= imagecreatefrompng($bigPath);
break;
}
switch($smallImgInfo[2]){
case 1:
$smallImg= imagecreatefromgif($smallPath);
break;
case 2:
$smallImg= imagecreatefromjpeg($smallPath);
break;
case 3:
$smallImg= imagecreatefrompng($smallPath);
break;
}
switch ($pos) {
case 1://左上角
imagecopy($bigImg, $smallImg, 0, 0, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //左上角
break;
case 2://右上角
imagecopy($bigImg, $smallImg, $bigImgInfo[0] - $smallImgInfo[0], 0, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //右上角=大图宽-小图宽 , 0
break;
case 3://右下角
imagecopy($bigImg, $smallImg, $bigImgInfo[0] - $smallImgInfo[0], $bigImgInfo[1] - $smallImgInfo[1], 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //右下角=大图宽-小图宽 , 大图高-小图高
break;
case 4://左下角
imagecopy($bigImg, $smallImg, 0, $bigImgInfo[1] - $smallImgInfo[1], 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //左下角=0 , 大图高-小图高
break;
case 5://居中
imagecopy($bigImg, $smallImg, ($bigImgInfo[0] - $smallImgInfo[0]) / 2, ($bigImgInfo[1] - $smallImgInfo[1]) / 2, 0, 0, $smallImgInfo[0], $smallImgInfo[1]); //居中=(大图宽-小图宽)/2 , (大图高-小图高)/2
break;
}
$newName = md5(uniqid()) . '.png';//已添加的水印图片新
$savePath = $rootPath . '/upload/water/';//已添加的水印图片保存目录
if (!is_dir($savePath)) {
if (!mkdir($savePath, 0777, true)) {
$_SESSION['fileerror']= 12;
header('location:../after_end/info.php');
exit();
}
}
$r =imagepng($bigImg, $savePath.$newName); //把已添加水印的图片保存到磁盘中
imagedestroy($bigImg);
imagedestroy($smallImg);
if ($r) {
return '/upload/water/'.$newName;//前端绝对路径
} else {
$_SESSION['fileerror']= 12;
header('location:../after_end/info.php');
exit();
}
}