Heim > Backend-Entwicklung > PHP-Tutorial > 为你讲解PHP给图片加水印的具体方法_PHP教程

为你讲解PHP给图片加水印的具体方法_PHP教程

WBOY
Freigeben: 2016-07-15 13:29:09
Original
951 Leute haben es durchsucht

我们在做网站的时候,都会遇到需要将网站上传的图片附加上水印,如果一个一个的手工加水印肯定非常麻烦,也是不实际的操作。那么,我们今天就向大家接受PHP给图片加水印的具体方法,简化操作步骤。

  • 给图片加水印的具体代码如下:

    <ol class="dp-xml">
    <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span>   </span></span></li>
    <li class=""><span>/******************************************************************************   </span></li>
    <li class="alt"><span> </span></li>
    <li class=""><span>参数说明:   </span></li>
    <li class="alt"><span>$max_file_size  : 上传文件大小限制, 单位BYTE   </span></li>
    <li class=""><span>$destination_folder : 上传文件路径   </span></li>
    <li class="alt"><span>$watermark   : 是否附加水印(1为加水印,其他为不加水印);   </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>使用说明:   </span></li>
    <li class="">
    <span>1. 将PHP.INI文件里面的"</span><span class="attribute"><font color="#ff0000">extension</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">php_gd2</font></span><span>.dll"一行前面的;号去掉,因为我们要用到GD库;   </span>
    </li>
    <li class="alt">
    <span>2. 将</span><span class="attribute"><font color="#ff0000">extension_dir</font></span><span> =改为你的php_gd2.dll所在目录;   </span>
    </li>
    <li class=""><span>******************************************************************************/   </span></li>
    <li class="alt"><span> </span></li>
    <li class=""><span>//上传文件类型列表   </span></li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">uptypes</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">array</font></span><span>(   </span>
    </li>
    <li class=""><span>    'image/jpg',   </span></li>
    <li class="alt"><span>    'image/jpeg',   </span></li>
    <li class=""><span>    'image/png',   </span></li>
    <li class="alt"><span>    'image/pjpeg',   </span></li>
    <li class=""><span>    'image/gif',   </span></li>
    <li class="alt"><span>    'image/bmp',   </span></li>
    <li class=""><span>    'image/x-png'   </span></li>
    <li class="alt"><span>);   </span></li>
    <li class=""><span> </span></li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">max_file_size</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">2000000</font></span><span>;     //上传文件大小限制, 单位BYTE   </span>
    </li>
    <li class="">
    <span>$</span><span class="attribute"><font color="#ff0000">destination_folder</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"uploadimg/"</font></span><span>; //上传文件路径   </span>
    </li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">watermark</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span>;      //是否附加水印(1为加水印,其他为不加水印);   </span>
    </li>
    <li class="">
    <span>$</span><span class="attribute"><font color="#ff0000">watertype</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span>;      //水印类型(1为文字,2为图片)   </span>
    </li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">waterposition</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span>;     //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);   </span>
    </li>
    <li class="">
    <span>$</span><span class="attribute"><font color="#ff0000">waterstring</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"http://www.xplore.cn/"</font></span><span>;  //水印字符串   </span>
    </li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">waterimg</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"xplore.gif"</font></span><span>;    //水印图片   </span>
    </li>
    <li class="">
    <span>$</span><span class="attribute"><font color="#ff0000">imgpreview</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span>;      //是否生成预览图(1为生成,其他为不生成);   </span>
    </li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">imgpreviewsize</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span>/2;    //缩略图比例   </span>
    </li>
    <li class="">
    <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
    </li>
    <li class="alt">
    <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span>   </span>
    </li>
    <li class="">
    <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span></span></font></strong><span>   </span>
    </li>
    <li class="alt">
    <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></font></strong><span>ZwelL图片上传程序</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span></font></strong><span>   </span>
    </li>
    <li class="">
    <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">style</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"text/css"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span>   </span>
    </li>
    <li class="alt"><span></span></li>
    </ol>
    Nach dem Login kopieren
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage