首页 > 后端开发 > php教程 > PHP图片加水印代码示例解析_PHP教程

PHP图片加水印代码示例解析_PHP教程

WBOY
发布: 2016-07-15 13:33:20
原创
874 人浏览过

一个正规的网站,在需要上传图片时,往往都会需要在图片上增加自己网站的LOGO水印。那么如何实现这一步骤呢?首先让我们来了解

通过判断文件类型建立图形,然后把其复制到原建立的图形上,填充并建立rectangle,以备写入imagestring()或是在原已经定好的图像程序当中判断水印类型:一是字符串,另是增加一个图形对象在上面。以下是PHP图片加水印的转载!

参数说明:

$max_file_size : 上传文件大小限制, 单位BYTE
$destination_folder : 上传文件路径
$watermark : 是否附加水印(1为加水印,其他为不加水印);

PHP图片加水印使用说明:

1. 将PHP.INI文件里面的"extension=php_gd2.dll"一行前面的;号去掉,因为我们要用到GD库;
2. 将extension_dir =改为你的php_gd2.dll所在目录;

PHP图片加水印的代码示例:

<ol class="dp-xml">
<li class="alt"><span><span>//上传文件类型列表     </span></span></li>
<li>
<span>$</span><span class="attribute">uptypes</span><span>=</span><span class="attribute-value">array</span><span>(     </span>
</li>
<li class="alt"><span>'image/jpg',     </span></li>
<li><span>'image/jpeg',     </span></li>
<li class="alt"><span>'image/png',     </span></li>
<li><span>'image/pjpeg',     </span></li>
<li class="alt"><span>'image/gif',     </span></li>
<li><span>'image/bmp',     </span></li>
<li class="alt"><span>'image/x-png'     </span></li>
<li><span>);     </span></li>
<li class="alt">
<span>$</span><span class="attribute">max_file_size</span><span>=</span><span class="attribute-value">2000000</span><span>; //上传文件大小限制, 单位BYTE     </span>
</li>
<li>
<span>$</span><span class="attribute">destination_folder</span><span>=</span><span class="attribute-value">"uploadimg/"</span><span>; //上传文件路径     </span>
</li>
<li class="alt">
<span>$</span><span class="attribute">watermark</span><span>=</span><span class="attribute-value">1</span><span>; //是否附加水印(1为加水印,其他为不加水印);     </span>
</li>
<li>
<span>$</span><span class="attribute">watertype</span><span>=</span><span class="attribute-value">1</span><span>; //水印类型(1为文字,2为图片)     </span>
</li>
<li class="alt">
<span>$</span><span class="attribute">waterposition</span><span>=</span><span class="attribute-value">1</span><span>; //水印位置(1为左下角,2为右下角  </span>
</li>
<li><span>,3为左上角,4为右上角,5为居中);     </span></li>
<li class="alt">
<span>$</span><span class="attribute">waterstring</span><span>="</span><span class="tag"><span> </span><span class="tag-name">A</span><span> href="</span><span class="attribute-value">http</span><span>://www.xplore.cn/"</span><span class="tag">></span><span> </span></span>
</li>
<li>
<span>http://www.xplore.cn/</span><span class="tag"><span> /A</span><span class="tag">></span><span>"; //水印字符串     </span></span>
</li>
<li class="alt">
<span>$</span><span class="attribute">waterimg</span><span>=</span><span class="attribute-value">"xplore.gif"</span><span>; //水印图片     </span>
</li>
<li>
<span>$</span><span class="attribute">imgpreview</span><span>=</span><span class="attribute-value">1</span><span>; //是否生成预览图(1为生成,其他为不生成);     </span>
</li>
<li class="alt">
<span>$</span><span class="attribute">imgpreviewsize</span><span>=</span><span class="attribute-value">1</span><span>/2; //缩略图比例     </span>
</li>
<li>
<span class="tag">?></span><span>     </span>
</li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">html</span><span class="tag">></span><span>     </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">head</span><span class="tag">></span><span>     </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">title</span><span class="tag">></span><span>ZwelL图片上传程序</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span>     </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">style</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span class="tag">></span><span>     </span></span></li>
<li class="alt"><span></span></li>
</ol>
登录后复制
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板