代码如下,图片文件大小实在太大了,影响手机浏览速度。
看了其他手机站发现图片基本上都控制在二三十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;
    }

解决方案 »

  1.   

    补充一下~ 我用的是Thinkphp的框架~  GD库~ 
      

  2.   

    一个是图片大小,不要超过河流使用范围,另一个jpg图片的质量,60%最佳,但不要给处女座看到
      

  3.   

    参考:
    http://blog.csdn.net/fdipzone/article/details/9316385
    看你需求,应该是调整quality参数即可。
      

  4.   

    安装imagick 这个就省去了图像处理的麻烦 而且还能保证图片的质量
      

  5.   

    http://www.thinkphp.cn/extend/238.html
      

  6.   

    //设置缩略图最大宽度
    $upload->thumbMaxWidth = '400,100';
    //设置缩略图最大高度
    $upload->thumbMaxHeight = '400,100';