对图片进行等比例缩小
来源:互联网 发布:dota和dota2区别 知乎 编辑:程序博客网 时间:2024/05/22 06:45
/** * 上传文件 * @return string */public function uploadFile() { if($this->checkError() && $this->checkSize() && $this->checkExt() && $this->checkMime() && $this->checkTrueImg() && $this->checkHTTPPost()) { $this->checkUploadPath(); $this->uniName = $this->fileInfo['name'];//图片名字 $this->destination = $this->uploadPath . '/' . $this->uniName; if(@move_uploaded_file($this->fileInfo['tmp_name'], $this->destination)) { $im = $this->destination; $tofile = $this->uploadPath . '/'.'tmp'.'/'. $this->uniName ; $maxwidth = 600; //设置图片的最大宽度 $maxheight = 800; //设置图片的最大高度 $res = $this->resize($im,$tofile,$maxwidth,$maxheight,''); if($res) return $res; else $this->error = '014'; $this->showError(); } else { $this->error = '013'; $this->showError(); } } else { $this->showError(); }}/** * 设置宽高 按比例缩放 */function resize($srcImage,$toFile,$maxWidth = 100,$maxHeight = 100,$imgQuality=100){ list($width, $height, $type, $attr) = getimagesize($srcImage); if($width < $maxWidth || $height < $maxHeight) return ; switch ($type) { case 1: $img = imagecreatefromgif($srcImage); break; case 2: $img = imagecreatefromjpeg($srcImage); break; case 3: $img = imagecreatefrompng($srcImage); break; } $scale = min($maxWidth/$width, $maxHeight/$height); //求出绽放比例 if($scale < 1) { $newWidth = floor($scale*$width); $newHeight = floor($scale*$height); $newImg = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $newName = ""; $toFile = preg_replace("/(.gif|.jpg|.jpeg|.png)/i","",$toFile); switch($type) { case 1: if(imagegif($newImg, "$toFile$newName.gif" )) return "$toFile$newName.gif"; break; case 2: if(imagejpeg($newImg, "$toFile$newName.jpg")) return "$toFile$newName.jpg"; break; //case 3: if(imagepng($newImg, "$toFile$newName.png", $imgQuality)) case 3: if(imagepng($newImg, "$toFile$newName.png")); return "$toFile$newName.png"; break; default: if(imagejpeg($newImg, "$toFile$newName.jpg")) return "$toFile$newName.jpg"; break; } imagedestroy($newImg); } imagedestroy($img); return false;}
阅读全文
0 0
- 对图片进行等比例缩小
- //等比例缩小图片
- 图片等比例缩小
- 判断图片等比例缩小
- iphone 图片等比例缩小
- 设置图片等比例缩小
- CSS强制等比例缩小图片
- Node.js等比例放倒缩小图片
- CSS强制等比例缩小图片
- 对图片进行等比例缩放,并水平垂直居中
- jQuery 让图片等比例缩小,让所有图片都等比例缩小
- 将图片等比例缩小不影响图片的分辨率
- ImageView等比例缩小
- bitmap等比例缩小
- 计算图片缩小比例
- js+css图片自动等比例缩小且垂直居中
- js+css图片自动等比例缩小且垂直居中
- 图片不变形,按照等比例缩小或扩大显示
- [LeetCode]191. Number of 1 Bits
- Hibernate关系映射级别注解(一对一双向外键关联、一对一双向外键联合主键)
- vector查找数据并返回索引
- 笔记20 | 学习整理开源APP(BaseAnimation)程序源码“中的通讯录效果
- ES6之Promise
- 对图片进行等比例缩小
- C语言学习笔记(六)——文件操作
- python Flask-SQLAlchemy 连接数据库
- Easyui Datagrid 表头和表体列对照异常
- 分享一个sqlsever DBA的blog,东西挺全面
- C++ typedef struct 引起的expected unqualified-id before...错误
- 感知器算法
- 关于Influxdb
- leetcode 69