php为图片加水印
<?phpfunction Stamp($imgFile)
{
//$imgFile = ROOTPATH.$imgFile;
//文件扩展名
$extName = substr($imgFile,strrpos($imgFile,'.'));
$extName = strtolower($extName);
$extName = ('.jpeg' == $extName) ? '.jpg' : $extName;
//载入图片的方法
$createFun = 'imagecreatefrom'.substr($extName,1);
if(!function_exists($createFun))
{
$createFun = 'imagecreatefromjpeg';
}
//载入图片
$srcImg = $createFun($imgFile);
//原图大小
list($srcWidth, $srcHeight) = getimagesize($imgFile);
//水印图片
$stampImg = imagecreatefrompng('1.png');
imagecopymerge($srcImg,$stampImg,10,10,0,0,141,140,100);
$stampImgPath = substr($imgFile,0,strrpos($imgFile,'.'));
$stampImgPath .= '-stamp.jpg';
imagejpeg($srcImg,$stampImgPath,100);
imagedestroy($srcImg);
imagedestroy($stampImg);
}
Stamp('1.jpg');