示例#1
0
文件: File.php 项目: xswolf/baihey
 /**
  * 后台压缩图片处理
  * @param $tempFile 原文件
  * @param $extension 后缀名
  */
 public function backThumbImage($tempFile, $extension)
 {
     $imagePath = $this->getImagePath(__DIR__ . "/../../images/");
     $targetFile = $imagePath . '.' . $extension;
     // 上传图片
     if (move_uploaded_file($tempFile, $targetFile)) {
         $fileInfo = getimagesize($targetFile);
         // 重命名加上图片长宽
         $picInfo = $this->pictureRatio($fileInfo[0], $fileInfo[1]);
         //  等比例
         $picturePath = $imagePath . '_' . $picInfo[0] . '_' . $picInfo[1] . '.' . $extension;
         if (rename($targetFile, $picturePath)) {
             //$thumbInfo = $this->thumbRation($fileInfo[0], $fileInfo[1]);//缩略图尺寸
             //$thumbInfo = $this->pictureRatio($fileInfo[0], $fileInfo[1], 267, 200);//缩略图尺寸
             // 固定压缩图片长宽200
             //$image = new Image();
             $thumbPath = str_replace('picture', 'thumb', $picturePath);
             //$image->open($picturePath);
             //$image->thumb($thumbInfo[0], $thumbInfo[1], $image::IMAGE_THUMB_FIXED)->save($thumbPath);
             //$image->thumb(200, 200, $image::IMAGE_THUMB_CENTER)->save($thumbPath);// 居中裁剪
             $pic = new Image();
             $pic->open($picturePath);
             $pic->thumb($picInfo[0], $picInfo[1], $pic::IMAGE_THUMB_FIXED)->save($picturePath);
             //原图压缩
             //                $pic->water(__DIR__."/../../wechat/web/images/logo_water.png")->save($picturePath);
             $pic->thumb(200, 200, $pic::IMAGE_THUMB_FIXED)->save($thumbPath);
             // 居中裁剪
             //                $pic->water(__DIR__."/../../wechat/web/images/logo_water.png")->save($thumbPath);
         }
     }
     $thumbArr = explode('/../..', $thumbPath);
     echo $thumbArr[1];
     // 返回压缩图片路径
 }
 function execute()
 {
     Image::buildImageVerify(4, 0, 'png', 50, 24, '_verifyCode');
 }