代码如下,图片文件大小实在太大了,影响手机浏览速度。
看了其他手机站发现图片基本上都控制在二三十k左右。
求助,要压缩到几十k需要怎么做?/**
* 上传图片
* @return array
*/
private function uploadImage($imageList) {
$rootPath = C('ROOT_PATH'); //图片上传根目录
//检测上传根目录
if(!$this->checkRootPath($rootPath)){
$this->errorAjaxReturn($this->getError());
}
$image = new \Think\Image();
/* 存储上传的图片列表 */
$rvArr = null;
for ($i=0; $i<count($imageList); $i++){
$savePath = $this->getSavePath($rootPath,'houses/'); //获取
$saveName = uniqid().'.jpg';
$sourceFile = $rootPath . $savePath . $saveName; //源文件
$thumbPath = $rootPath . $savePath . 'mini_' . $saveName; //缩略图路径
$img = base64_decode($imageList[$i]); //base64解码成图片
if (file_put_contents($sourceFile, $img) == false) { //存储图片
$this->errorAjaxReturn('上传失败');
}
//产生水印图
$image->open($sourceFile)->thumb(600, 600)->water('./res/img/login/logo_water.png',\Think\Image::IMAGE_WATER_NORTHWEST,40)->save($sourceFile);
//产生缩略图
$image->open($sourceFile)->thumb(300, 300)->save($thumbPath);
$rvArr[] = array('rootPath'=>$rootPath,
'savePath'=>$savePath,
'saveName'=>$saveName
);
}
return $rvArr;
}
看了其他手机站发现图片基本上都控制在二三十k左右。
求助,要压缩到几十k需要怎么做?/**
* 上传图片
* @return array
*/
private function uploadImage($imageList) {
$rootPath = C('ROOT_PATH'); //图片上传根目录
//检测上传根目录
if(!$this->checkRootPath($rootPath)){
$this->errorAjaxReturn($this->getError());
}
$image = new \Think\Image();
/* 存储上传的图片列表 */
$rvArr = null;
for ($i=0; $i<count($imageList); $i++){
$savePath = $this->getSavePath($rootPath,'houses/'); //获取
$saveName = uniqid().'.jpg';
$sourceFile = $rootPath . $savePath . $saveName; //源文件
$thumbPath = $rootPath . $savePath . 'mini_' . $saveName; //缩略图路径
$img = base64_decode($imageList[$i]); //base64解码成图片
if (file_put_contents($sourceFile, $img) == false) { //存储图片
$this->errorAjaxReturn('上传失败');
}
//产生水印图
$image->open($sourceFile)->thumb(600, 600)->water('./res/img/login/logo_water.png',\Think\Image::IMAGE_WATER_NORTHWEST,40)->save($sourceFile);
//产生缩略图
$image->open($sourceFile)->thumb(300, 300)->save($thumbPath);
$rvArr[] = array('rootPath'=>$rootPath,
'savePath'=>$savePath,
'saveName'=>$saveName
);
}
return $rvArr;
}
http://blog.csdn.net/fdipzone/article/details/9316385
看你需求,应该是调整quality参数即可。
$upload->thumbMaxWidth = '400,100';
//设置缩略图最大高度
$upload->thumbMaxHeight = '400,100';