Esempio n. 1
0
 /**
  * 图片裁剪
  */
 public function crop($subfix = '')
 {
     C('DEFAULT_AJAX_RETURN', 'json');
     $imgUrl = I('post.imgUrl');
     $image = file_read_remote($imgUrl);
     if ($image) {
         $param = array('width' => I('post.imgW', 0, 'ceil'), 'height' => I('post.imgH', 0, 'ceil'), 'y' => I('post.imgY1', 0, 'ceil'), 'x' => I('post.imgX1', 0, 'ceil'), 'w' => I('post.cropW', 0, 'ceil'), 'h' => I('post.cropH', 0, 'ceil'));
         $imgPath = UPLOAD_PATH . date('Y/m/d/') . basename($imgUrl);
         $newImage = file_subfix($imgPath, $subfix);
         $res = image_crop($param, $image, false, $newImage);
         if ($res) {
             $response = array('status' => 1, 'info' => '裁剪成功', 'url' => file_full_path($newImage));
         } else {
             $response = array('status' => 0, 'info' => '图片裁剪失败');
         }
     } else {
         $response = array('status' => 0, 'info' => '图片读取失败');
     }
     $this->ajaxReturn($response);
 }
Esempio n. 2
0
 /**
  * 远程图片上传到本地
  */
 public function remoteImage($url = '')
 {
     if (!IS_POST) {
         return false;
     }
     @set_time_limit(600);
     $reExt = '(' . implode('|', C('FILE_UPLOAD_IMG_CONFIG.exts')) . ')';
     $config = C('TMPL_PARSE_STRING');
     //base64图片内容上传
     if (substr($url, 0, 10) == 'data:image') {
         if (!preg_match('/^data:image\\/' . $reExt . '/i', $url, $sExt)) {
             $this->error('不支持的格式');
         }
         $sExt = $sExt[1];
         $imgContent = base64_decode(substr($url, strpos($url, 'base64,') + 7));
         //图片地址上传
     } else {
         preg_match("/\\.{$reExt}\$/i", $url, $sExt);
         if (!$sExt) {
             continue;
         }
         $sExt = $sExt[1];
         //先验证链接地址是否正确
         if (!file_exist_remote($url)) {
             $this->error('无效的链接');
         }
         $imgContent = file_read_remote($url);
     }
     $filename = date('Y/m/d/') . uniqid() . '.' . strtolower($sExt);
     file_write(UPLOAD_PATH . $filename, $imgContent);
     $this->water($filename);
     $this->success($config[UPLOAD_PATH] . $filename);
 }