//增加本地图片水印 www.5ucms.com
function addwatermark($savepath){
$picwatermarktype = C('picwatermarktype'); //读取配置 是否添加水印
if($picwatermarktype>0 and strstr($savepath,'uploadfile')){
$savepath = str_ireplace('./', '/', $savepath);
$savepath = '.'.$savepath;
$image = new \Think\Image();
$preimg = $image -> open($savepath);
if($preimg){
$picwatermarkimg = '.'.C('picwatermarkimg');//读取水印图片
$qid = $preimg -> water($picwatermarkimg,$picwatermarktype,C('picwatermarkalpha')) -> save($savepath);
if($qid){return true;}
}
}
return false;
}效果图http://php.5ucms.com/index.php/content/index/id/14
我用的gif加80半透明 感觉有毛边
还有个问题是 怎么让上方的函数出错时 不提示?
有时 原图找不到 或 水印图片找不到 就会报错 如果能作个判断呢?
图片能open就继续 不能open就返回false
最佳答案