经测试代码如下:
/**
* 生成水印
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
public function water($source,$water,$alpha=60){
if(!file_exists($source) && !file_exists($water)){
return false;
}
$sInfo = $this->getImageInfo($source);
$wInfo = $this->getImageInfo($water);
$sType = $sInfo['type'];
$wType = $wInfo['type'];
$sFun = "imagecreatefrom".$sType;
$sImage= $sFun($source);
$wFun = "imagecreatefrom".$wType;
$wImage= $wFun($water);
imagealphablending($wImage,true);
//图像位置,默认为右下角右对齐
$posX =$sInfo['width'] - $wInfo['width'];
$posY =$sInfo['height'] - $wInfo['height'];
imagecopymerge($sImage,$wImage,$posX,$posY,$wInfo['width'],$wInfo['height'],$alpha);
$ImageFun = 'Image' . $sInfo['type'];
$ImageFun($sImage);
imagedestroy($sImage);
imagedestroy($wImage);
}
原文链接:https://www.f2er.com/php/529036.html