上传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;

Hostodo美国独立日优惠套餐年付13.99美元起,拉斯维加斯/迈阿密机房

Hostodo又发布了几款针对7月4日美国独立日的优惠套餐(Independence Day Super Sale),均为年付,基于KVM架构,采用NVMe硬盘,最低13.99美元起,可选拉斯维加斯或者迈阿密机房。这是一家成立于2014年的国外VPS主机商,主打低价VPS套餐且年付为主,基于OpenVZ和KVM架构,产品性能一般,支持使用PayPal或者支付宝等付款方式。商家客服响应也比较一般,推...

EtherNetservers年付仅10美元,美国洛杉矶VPS/1核512M内存10GB硬盘1Gpbs端口月流量500GB/2个IP

EtherNetservers是一家成立于2013年的英国主机商,提供基于OpenVZ和KVM架构的VPS,数据中心包括美国洛杉矶、新泽西和杰克逊维尔,商家支持使用PayPal、支付宝等付款方式,提供 60 天退款保证,这在IDC行业来说很少见,也可见商家对自家产品很有信心。有需要便宜VPS、多IP VPS的朋友可以关注一下。优惠码SUMMER-VPS-15 (终身 15% 的折扣)SUMMER-...

Sharktech:美国/荷兰独立服务器,10Gbps端口/不限流量/免费DDoS防护60G,319美元/月起

sharktech怎么样?sharktech (鲨鱼机房)是一家成立于 2003 年的知名美国老牌主机商,又称鲨鱼机房或者SK 机房,一直主打高防系列产品,提供独立服务器租用业务和 VPS 主机,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹,所有产品均提供 DDoS 防护。此文只整理他们家10Gbps专用服务器,此外该系列所有服务器都受到高达 60Gbps(可升级到 100Gbps)的保护。...

上传工具为你推荐
fontfamilyfont-family:"microsoft yahei",simhei; 这句到底设置为微软雅黑还是黑体,为什么写2个字体?cornerradiusUG后处理可以输出自定义刀具描述吗?windows优化大师怎么用windows优化大师怎么用啊?显卡温度多少正常显卡温度多少算正常?苹果5怎么越狱苹果5怎么越狱?qq怎么发邮件qq怎么发文件和邮件开机滚动条开机滚动条太多怎么办?奇虎论坛奇虎问答是什么创维云电视功能什么是创维云电视啊?创维云电视是什么意思?人人逛街包公免费逛街打一成语
3322动态域名注册 最新代理服务器ip 淘宝二级域名 如何注册中文域名 优惠码 香港托管 免费名片模板 免费博客空间 web服务器架设软件 丹弗 华为4核 促正网秒杀 网通服务器托管 双12 免费外链相册 架设邮件服务器 丽萨 lamp架构 创速 好看的空间 更多