Home > php教程 > php手册 > body text

PHP判断来源显示图片水印

WBOY
Release: 2016-06-21 08:50:17
Original
1475 people have browsed it

 

// # 配置文件 php100.com

 

$floder = ''; #图片保存文件夹 

 

$waterpic = 'win.png'; #水印图片地址 

 

$referer = 'kalvin'; #来源页包含字符串 

 

// # 配置文件 

 

header("Content-type: image/png"); # 设置输出文件头 

 

$filename = $floder . $_GET["filename"]; # 设置源文件地址 

 

$sourceImg = imagecreatefromjpeg($filename); # 读取源图像 

 

$waterImg = imagecreatefrompng($waterpic); # 读取水印标志 

 

$bg_color = imagecolorat($waterImg, 1, 1); # 取出标志中需要设为透明的颜色 

 

imagecolortransparent($waterImg, $bg_color); # 设置标志中需要透明的颜色 

 

$sourceX = imagesx($sourceImg); # 取得源图像宽度 

 

$sourceY = imagesy($sourceImg); # 取得源图像高度 

 

$waterX = imagesx($waterImg); # 取得标志像宽度 

 

$waterY = imagesy($waterImg); # 取得标志像高度 

 

$x = ($sourceX - $waterX) / 2; 

$y = ($sourceY - $waterY) / 2; #计算中心位置 

 

if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $referer) == false) 

    imagecopymerge($sourceImg, $waterImg, $x, $y, 0, 0, $waterX, $waterY, 80); #合并图像 合并度设置为50 .100为完全合并.相当于把第二个参数里的图像透明到原来的50/100然后贴到第一个参数的图像里 

 

imagepng($sourceImg); #输出图像 php100.com

 

?> 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template