php上传图片加水印(图片水印,文字水印) 这是一款比较完整理的在用户上传图片时就自动给图片增加上水印,这款增加水印功能可以增加文字水印与图片水印哦。
php教程上传图片加水印(图片水印,文字水印)
这是一款比较完整理的在用户上传图片时就自动给图片增加上水印,这款增加水印功能可以增加文字水印与图片水印哦。
/*
* created on 2010-6-21
*
* the class for control image
*
* made by s71ence
*
* @$img_path 图片路径
* @$is_auto_reduce 图片是否自动按照大小等级压缩 1是
* @$is_appoint 是否手动进行压缩或放大 1是
* @$multiple 手动指定压缩/放大比例
* @$is_water_str 是否加水印文字 1是
* @$water_str 水印文字
* @$is_watermark 是否加水印图片 1是
* @$logo_path 水印图片路径
* @$is_display 是否显示图片 1是
* @$is_create 是否生成压缩后的图片 1是
*
* 注:
* 1.生成新图时不可显示图片,即$isdisplay和$iscreate不可同时置为1
* 2.当图片宽或高小于1000时,需手动设置压缩比例进行压缩
* 3.不建议启用水印,若要启用,建议原图片大小最好在1000以内
* 4.水印文字中不可含有中文
* 5.新生成的图片在原目录文件中,支持n个层级
*/class image_control
{
private $img_path;
private $is_auto_reduce;
private $is_appoint;
private $multiple;
private $is_water_str;
private $water_str;
private $is_watermark;
private $logo_path;
private $is_display;
private $is_create;function __construct($img_path,$is_auto_reduce,$is_appoint,$multiple,$is_water_str,$water_str,$is_watermark,$logo_path,$is_display,$is_create)
{
$this->img_path=$img_path;
$this->is_auto_reduce=$is_auto_reduce;
$this->is_appoint=$is_appoint;
$this->multiple=$multiple;
$this->is_water_str=$is_water_str;
$this->water_str=$water_str;
$this->is_watermark=$is_watermark;
$this->logo_path=$logo_path;
$this->is_display=$is_display;
$this->is_create=$is_create;
}function img_control()
{
//获取原图
$img_info=getimagesize($this->img_path);switch($img_info[2])
{
case 1:
$img_get=@imagecreatefromgif($this->img_path);
break;case 2:
$img_get=@imagecreatefromjpeg($this->img_path);
break;case 3:
$img_get=@imagecreatefrompng($this->img_path);
break;
}//文字水印
if($this->is_water_str==1)
{
//imagettftext(原图,文字大小,文字旋转,水印起始坐标x,水印起始坐标y,$te,'simhei.ttf',$str);
$te=imagecolorallocate($img_get,255,255,255);
$str=iconv("gbk","utf-8",$this->water_str);//水印文字
imagettftext($img_get,16,0,$img_info[0]-200,$img_info[1]-20,$te,'msyh.ttf',$str);
}//图片水印
if($this->is_watermark==1)
{
//水印图片处理
$logo_info=getimagesize($this->logo_path);switch($logo_info[2])
{
case 1:
$logo=@imagecreatefromgif($this->logo_path);
break;case 2:
$logo=@imagecreatefromjpeg($this->logo_path);
break;case 3:
$logo=@imagecreatefrompng($this->logo_path);
break;
}//水印logo图片
//函数说明:imagecopy(原图,水印图片,水印坐标x,水印坐标y,水印图片开始坐标x,水印图片开始坐标y,'水印图片宽','水印图片高');
imagecopy($img_get,$logo,0,0,0,0,$logo_info[0],$logo_info[1]);
}//自动图片压缩 按图片大小分级自动压缩
//imagecopyresized(画布,原图,画布起始x坐标,画布起始y坐标,原图起始x坐标,原图起始x坐标,新图片宽,新图片高,原图片宽,原图片高);
if($this->is_auto_reduce==1)
{
if($img_info[0]>=3000 || $img_info[1]>=3000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.03,$img_info[1]*0.03);//生成画布
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.03,$img_info[1]*0.03,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=2500 || $img_info[1]>=2500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.04,$img_info[1]*0.04);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.04,$img_info[1]*0.04,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=2000 || $img_info[1]>=2000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.05,$img_info[1]*0.05);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.05,$img_info[1]*0.05,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=1500 || $img_info[1]>=1500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.08,$img_info[1]*0.08);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.08,$img_info[1]*0.08,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=1000 || $img_info[1]>=1000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.1,$img_info[1]*0.1);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.1,$img_info[1]*0.1,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=500 || $img_info[1]>=500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.2,$img_info[1]*0.2);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.2,$img_info[1]*0.2,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=300 || $img_info[1]>=300)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.3,$img_info[1]*0.3);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.3,$img_info[1]*0.3,$img_info[0],$img_info[1]);
}
else
{
$new_image_get=imagecreatetruecolor($img_info[0]*1,$img_info[1]*1);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*1,$img_info[1]*1,$img_info[0],$img_info[1]);
}
}//手动图片压缩
//imagecopyresized(画布,原图,画布起始x坐标,画布起始y坐标,原图起始x坐标,原图起始x坐标,新图片宽,新图片高,原图片宽,原图片高);
if($this->is_appoint)
{
$new_image_get=imagecreatetruecolor($img_info[0]*$this->multiple,$img_info[1]*$this->multiple);//生成画布
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*$this->multiple,$img_info[1]*$this->multiple,$img_info[0],$img_info[1]);
}//图像输出
if($this->is_display==1)
{
header("content-type: image/jpeg");
return imagejpeg($new_image_get);
}//新图像生成
if($this->is_create==1)
{
$new_name=explode("/",$this->img_path);
$new_name_string="";for($i=0;$i
{
$new_name_string.=$new_name[$i]."/";
}$new_img_path=$new_name_string."new".$new_name[$i];
if(imagejpeg($new_image_get,$new_img_path) && imagejpeg($img_get,$this->img_path))
{
setcookie("img_new_path", $new_img_path);
//return "图片生成成功!
新图:".$new_img_path."
原图:".$this->img_path;
}
else
{
return "图片生成失败,请检查配置是否正确!";
}
}
}function __desctruct()
{
//clear
}
}
//调用方法
/* $img_path="../users/user_photo/t2.jpg"; //被操作的图片路径
$is_auto_reduce=1;//图片是否自动按照大小等级压缩 1是
$is_appoint=0;//是否手动进行压缩 1是
$multiple=0.5;//手动指定压缩比例
$is_water_str=0;//是否加水印文字
$water_str="www.bKjia.c0m";//水印文字
$is_watermark=0;//是否加水印图片 1是
$logo_path="../image/logo_about.gif";//水印图片路径
$is_display=0;//是否显示图片 1是
$is_create=1;//是否生成压缩后的图片 1是
$img=new image_control($img_path,$is_auto_reduce,$is_appoint,$multiple,$is_water_str,$water_str,$is_watermark,$logo_path,$is_display,$is_create);
echo $img->img_control();*/

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

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

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

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

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

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

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

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

Atom编辑器mac版下载
最流行的的开源编辑器

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver Mac版
视觉化网页开发工具