在某站看到,所以分享到四福,希望大家不要介意。有时候上传图片的时候,需要给图片加水印。水印一般为文字或图片标识水印。让我们来看看这两种添加方法。1、文字水印文字水印是在图片上添加文字,主要使用gd库的imagefttext方法,需要字体文件。效果图如下://以该地址的图片为例,$dst_path为图片文件名!$dst_path='https://www.dchuanbao.com/xy/704302224';//创建图片示例$dst=imagecreatefromstring(file_get_contents($dst_path));//添加文字需要字体文件$font='西姆森。ttc';//字体路径$black=imagecolorallocate($dst,0x00,0x00,0x00);//字体颜色imagefttext($dst,13,0,20,20,$black,$font,'[www.dchuanbao.com](https://www.dchuanbao.com/)');//输出图片列表($dst_w,$dst_h,$dst_type)=getimagesize($dst_path);switch($dst_type){case1://GIFheader('Content-Type:image/gif');imagegif($dst);break;case2://JPGheader('Content-Type:image/jpeg');imagejpeg($dst);休息;case3://PNGheader('Content-Type:image/png');imagepng($dst);中断;默认:中断;}imagedestroy($dst);如果要保存文件,添加imagepng作为参数imagepng(image,filename|quality|foreground);imagepng有4个参数image---要输出的图片资源,如imagecreate()或imagecreatefrom系列函数的返回值filename----可选,指定输出图片的文件名。如果省略,将直接输出原始图像流。quality----可选,指定图像质量,范围从0(最差质量,最小文件)到100(最佳质量,最大文件),默认75,imagejpeg()唯一参数foreground----可选,指定前景色,默认前景色为黑色,其余imagewbmp()特有参数自行发挥~
