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

ucloud香港服务器优惠活动:香港2核4G云服务器低至358元/年,968元/3年

ucloud香港服务器优惠降价活动开始了!此前,ucloud官方全球云大促活动的香港云服务器一度上涨至2核4G配置752元/年,2031元/3年。让很多想购买ucloud香港云服务器的新用户望而却步!不过,目前,ucloud官方下调了香港服务器价格,此前2核4G香港云服务器752元/年,现在降至358元/年,968元/3年,价格降了快一半了!UCloud活动路子和阿里云、腾讯云不同,活动一步到位,...

#消息# contabo:德国老牌机房新增美国“纽约、西雅图”数据中心,免设置费

运作了18年的德国老牌机房contabo在继去年4月开办了第一个美国数据中心(中部城市:圣路易斯)后立马在本月全新上马两个数据中心:纽约、西雅图。当前,为庆祝美国独立日,美国三个数据中心的VPS全部免除设置费,VPS本身的配置很高,价格适中,有较高的性价比!官方网站:https://contabo.com/en/SSD VPSKVM虚拟,纯SSD阵列,不限制流量,自带一个IPv4内存CPUSSD带...

器安装环境和运维管理工具推荐

今天看到一个网友从原来虚拟主机准备转移至服务器管理自己的业务。这里问到虚拟主机和服务器到底有什么不同,需要用到哪些工具软件。那准备在下班之间稍微摸鱼一下整理我们服务器安装环境和运维管理中常见需要用到的软件工具推荐。第一、系统镜像软件一般来说,我们云服务器或者独立服务器都是有自带镜像的。我们只需要选择镜像安装就可以,比如有 Windows和Linux。但是有些时候我们可能需要自定义镜像的高级玩法,这...

上传工具为你推荐
ghostxp3GHOSTxp sp3系统有什么优点和缺点???自助建站自助建站到底好还是不好淘宝网页显示不正常淘宝网页不能正常显示mate8价格华为mate8 128g售价多少钱mate8价格华为mate8市场价多少网页打开很慢为什么我打开网页很慢系统分析员系统分析员的工作内容虚拟机软件下载谁有好用的虚拟机软件?网络虚拟机虚拟机网络怎么连接Qzongqzong皮肤上怎样写字
秒解服务器 网站监控 万网优惠券 远程登陆工具 服务器架设 租空间 中国电信宽带测速网 免费网页申请 帽子云排名 申请免费空间 浙江服务器 cdn网站加速 免费稳定空间 云服务是什么意思 七十九刀 xshell5注册码 亿库 最新优惠 超低价 linuxvi 更多