上传php上传图片,生成略缩图,加水印工具类

上传工具  时间:2021-02-23  阅读:()

PHP上传图片生成略缩图加水印工具类var$annexF older=upload//附件存放点默认为 annexvar $smallFolder=small //缩略图存放路径注必须是放在$annexFolder下的子目录默认为 smallimgvar$markF older=mark//水印图片存放处var$upFileType=jpg gif png//上传的类型默认为 jpg gif png rar zipvar$upFileMax=1024;//上传大小限制单位是“KB”默认为 1024KBvar$fontTyp e;//字体v ar$m ax Width=500; //图片最大宽度var$maxHeight=600; //图片最大高度function UpImages($annexFolder,$smallFo lder,$includeFo lder) {

$this-annexF older=$annexF older;

$this- smallF o lder=$smallF o lder;

$this-fontType=$inc ludeFolder. /04B_08__.TTFfunc tion upLoad($inputName) {

$imageName=time();//设定当前时间为图片名称if(@empty($_F I LES[$inputName][name]))die(没有上传图片信息请确认

$name=explode( . ,$_FILES[$inputName][name ]);//将上传前的文件以“.”分开取得文件类型

$imgCount=c ount($name);//获得截取的数量

$imgTyp e=$name[$imgCount-1];//取得文件的类型if(s trp os($this- upF ileTyp e,$imgTyp e) === fals e) die(error(上传文件类型仅支持.$this-upFileType.不支持.$imgType));

$photo=$imageName. . .$imgType;//写入数据库的文件名

$uploadFile=$this-annexFolder. / .$photo;//上传后的文件名称

$upFileok=move_uploaded_file($_FILES[$inputName][ tmp_name],$uploadFile);if($upFileok) {

$imgSize=$_FILES[$inputName][ size

$kSize=round($imgSize/1024);if($kS ize($this-upF ile Max*1024)) {

@unlink($up lo adF il e);die(error(上传文件超过.$this-upF ileMax.KB));

} els e {die(error(上传图片失败请确认你的上传文件不超过$upFileMax KB或上传时间超时));r eturn$photo;function getInfo($photo) {

$photo=$this-annexF older. / .$photo;

$imageInfo=getimagesize($photo);

$imgInfo[w idth]=$imageInfo[0];

$imgInfo[height ]=$imageInfo[1];

$imgInfo[ typ e]=$imageInfo[2];

$imgInfo[name]=basename($photo);r eturn$imgI nfo;function smallImg($photo,$width=128,$height=128) {

$imgInfo=$this-getInfo($photo);

$photo=$this-annexF older. / .$photo;//获得图片源

$newName=s ub s tr($imgInfo[name],0,s trrpos($imgInfo[name], . ))._thumb.jpg//新图片名称if($im g I n fo[ typ e]==1) {

$img=imagecreatefromgif($photo);

} els eif($imgInfo[ type]==2) {

$img=imagecreatefromjpeg($photo);

} els eif($imgInfo[ type]==3) {

$img=imagecreatefrompng($photo);

} els e {

$img=if(empty($img)) return F als e;

$w idth=($w idth$imgI nfo[w idth]) ?$imgI nfo[w idth] :$w idth;

$height=($height$imgInfo[height ])?$imgInfo[height ] :$height;

$srcW=$imgInfo[width

$srcH=$imgInfo[heightif($src W*$w idth$s rc H* $height) {

$height=round($src H* $w idth/$src W);

} els e {

$w idth=round($src W* $height /$src H);if(func tion_exists( imagec reatetruec olor)) {

$newImg=imagec reatetruec olor($w idth, $height);

ImageCopyRes ampled($new Img, $img, 0, 0, 0, 0, $w idth, $height, $imgInfo[w idth ],$imgInfo[height ]);

} els e {

$newI mg=imag ec r eate($w idth,$height);

ImageCopyRes ized($new Img, $img, 0, 0, 0, 0, $w idth, $height, $imgInfo[ w idth ],$imgInfo[height ]);if($this- toF ile) {if (file_ex is ts($this- annexF older. / .$this- s mallF older. / .$newName))@unlink($this-annexFolder. / .$this- smallFo lder. / .$newName);

ImageJPEG($new Img,$this-annexFolder. / .$this- smallFold er. / .$newName);return$this-annexF older. / .$this- s mallF old er. / .$newName;

} els e {

ImageJPEG($newImg);

ImageDestroy($newImg);

ImageDestroy($img);r eturn$new Nam e;function waterMark($photo,$text) {

$imgInfo=$this-getInfo($photo);

$photo=$this-annexF older. / .$photo;

$newName=subs tr($imgInfo[name],0,s trrpos($imgInfo[name], . )) ._mark.jpgsw itch($imgInfo[ type]) {case 1:

$img=imagecreatefromgif($photo);break;case2:

$img=imagecreatefromjpeg($photo);break;case3:

$img=imagecreatefrompng($photo);break;default:r eturn F als e;if(empty($img))return F als e;

$w idth=($this-m axWidth$im g I n fo[w idth]) ?$im g I n fo[w idth] :$this-m axWidth;

$height=($this-maxHe ight$imgInfo[height ]) ?$img Info[height ] :$this-maxHe ight;

$srcW=$imgInfo[width

$srcH=$imgInfo[heightif($src W*$w idth$s rc H* $height) {

$height=round($src H* $w idth/$src W);

} els e {

$w idth=round($src W* $height /$src H);if(func tion_exists( imagecreatetruec olor)) {

$newImg=imagec reatetruec olor($w idth, $height);

ImageCopyRes ampled($new Img, $img, 0, 0, 0, 0, $w idth, $height, $imgInfo[w idth ],$imgInfo[height ]);

} els e {

$newI mg=imag ec r eate($w idth,$height);

ImageCopyRes ized($newImg, $img, 0, 0, 0, 0, $w idth, $height, $imgInfo[ w idth ],

$imgInfo[height ]);

$white=imageColorAllocate($newImg,255,255,255);

$black=imageColorAllocate($newImg,0,0,0);

$alpha=imageCo lorAlloc ateAlpha($newImg,230,230,230,40);

ImageF illedRec tangle($new Img,0, $height-26,$w idth, $height, $alpha);

ImageFilledRectangle($newImg, 13, $height-20, 15,$height-7, $black);

ImageT TF Text($new Img,4.9,0,20,$height-14, $blac k,$this-fontType, $text[0]);

ImageT TF Text($new Img,4.9,0,20,$height-6, $blac k,$this-fontType, $text[1]);if($this- toF ile) {if (file_ex is ts($this- annexF older. / .$this- markF older. / .$newName))@unlink($this-annexF older. / .$this-markF older. / .$newName);

ImageJPEG($new Img,$this-annexF older. / .$this-markF older. / .$newName);return$this-annexF o lder. / .$this-markF o lder. / .$new Name;

} els e {

ImageJPEG($newImg);

ImageDestroy($newImg);

ImageDestroy($img);r eturn$new Nam e;

wordpress外贸企业主题 wordpress经典外贸企业建站主题

WordPress经典外贸企业建站主题,经典配色扁平化简约设计+跨屏自适应移动端设备,特色外贸企业建站功能模块+在线Inquiry询单功能,更有利于Google等英文搜索优化和站点收录。采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器: IE 6+(以及类似360、遨游等基于IE内核的)、Firefox、Google Chrome、Safari、Opera等;同时支持移动终端的常用...

SpinServers(月89美元) 2*e5-2630L v2,美国独立服务器

SpinServers服务商也不算是老牌的服务商,商家看介绍是是2018年成立的主机品牌,隶属于Majestic Hosting Solutions LLC旗下。商家主要经营独立服务器租用和Hybrid Dedicated服务器等,目前包含的数据中心在美国达拉斯、圣何塞机房,自有硬件和IP资源等,商家还自定义支持用户IP广播到机房。看到SpinServers推出了美国独服的夏季优惠促销活动,最低月...

Pacificrack:新增三款超级秒杀套餐/洛杉矶QN机房/1Gbps月流量1TB/年付仅7美刀

PacificRack最近促销上瘾了,活动频繁,接二连三的追加便宜VPS秒杀,PacificRack在 7月中下旬已经推出了五款秒杀VPS套餐,现在商家又新增了三款更便宜的特价套餐,年付低至7.2美元,这已经是本月第三波促销,带宽都是1Gbps。PacificRack 7月秒杀VPS整个系列都是PR-M,也就是魔方的后台管理。2G内存起步的支持Windows 7、10、Server 2003\20...

上传工具为你推荐
伪装微信地理位置微信和微信伪装地理位置打不开怎么办?一点就一闪就完了万网核心代理我想买个域名和空间,我一朋友给我介绍万网代理环宇网络空间商,他们的空间稳定吗,价格怎么样,咨询师的服百度抢票浏览器现在火车票越来越难买了,新版百度手机浏览器,除了抢票外,还有什么其他功能吗?数码资源网手机练习打字的软件网易公开课怎么下载网易公开课的视频该如何下载?开机滚动条电脑开机有滚动条的画面mate8价格现在买华为mate8高配划算吗iphone6上市时间苹果6什么时候出来分词技术中文分词的应用分词技术搜索引擎采用的是什么技术?
虚拟主机软件 域名转让 网站域名备案 骨干网 腾讯云盘 12306抢票攻略 debian6 上海域名 双拼域名 秒杀汇 umax120 drupal安装 starry 论坛主机 lamp架构 深圳域名 黑科云 重庆联通服务器托管 2016黑色星期五 webmin 更多