您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

nginx如何通过PHP代理给图片加水印

2025/8/12 14:09:41发布26次查看
nginx 配置代理location ~ /image/.*\.(gif|jpg|jpeg|png)$ { proxy_pass http://127.0.0.1:8888/test/watermark?url=$request_uri;}
/img/ 匹配要代理的目录前缀,$request_uri 参数为访问的图片路径。
php 水印类/** 水印类 * class watermark * @package app\test */class watermark{ /** 合成图片水印 * @param string $dstimage 原图片 * @param string $waterimg 水印图 */ public static function imagemarking($dstimage, $waterimg){ //获取图片信息 $dstinfo = getimagesize($dstimage); $waterinfo = getimagesize($waterimg); //创建图像 $dstimgobj = self::imagecreatefrom($dstimage, $dstinfo[2]); $waterimgobj = self::imagecreatefrom($waterimg, $waterinfo[2]); //合成水印 imagecopyresized($dstimgobj,$waterimgobj,0, 0,0,0,$dstinfo[0], $dstinfo[1],$waterinfo[0],$waterinfo[1]); //输出图片 self::imageout($dstimgobj,$waterinfo[2]); //销毁资源对象 imagedestroy($dstimgobj); imagedestroy($waterimgobj); } /** 生成图片对象 * @param string $imgfile 图片路径 * @param string $type 图片类型 * @return false|\gdimage|resource */ private static function imagecreatefrom($imgfile, $type) { switch ($type) { case imagetype_gif: return imagecreatefromgif($imgfile); case imagetype_jpeg: return imagecreatefromjpeg($imgfile); case imagetype_png: return imagecreatefrompng($imgfile); default : //其他格式 } } /** 输出图片 * @param string $imageobj * @param string $type */ private static function imageout($imageobj,$type){ switch ($type) { case 1: header("content-type: image/gif"); imagegif($imageobj); break; case 2: header("content-type: image/jpeg"); imagejpeg($imageobj); break; case 3: header("content-type: image/png"); imagepng($imageobj); break; default: //其他格式 } }}
调用示例public function watermark(){ //图片路径前缀 $image = '/data/img/' . input('url'); self::imagemarking($image,'watermark.png'); exit;}
以上就是nginx如何通过php代理给图片加水印的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product