我们在做网站的时候,都会遇到需要将网站上传的图片附加上水印,如果一个一个的手工加水印肯定非常麻烦,也是不实际的操作。那么,我们今天就向大家接受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>

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version
