Ejemplo 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);
 }
Ejemplo n.º 2
0
 /**
  * 图片裁剪
  */
 public function crop($subfix = '')
 {
     $imgUrl = $_POST['imgUrl'];
     $imgW = ceil($_POST['imgW']);
     $imgH = ceil($_POST['imgH']);
     $imgY1 = ceil($_POST['imgY1']);
     $imgX1 = ceil($_POST['imgX1']);
     $cropW = ceil($_POST['cropW']);
     $cropH = ceil($_POST['cropH']);
     $response = array('status' => 'error', 'url' => 'Can`t write cropped File');
     $config = C('TMPL_PARSE_STRING');
     $imgPath = str_replace($config[UPLOAD_PATH], UPLOAD_PATH, $imgUrl);
     $image = file_read($imgPath);
     $output = file_subfix($imgPath, $subfix);
     if ($image) {
         $imagick = new ImageMagick();
         $imagick->read($image);
         $imagick->thumbnail($imgW, $imgH);
         $imagick->crop($imgX1, $imgY1, $cropW, $cropH);
         $res = file_write($output, $imagick->get_content());
         if ($res) {
             $response = array('status' => 'success', 'url' => $config[UPLOAD_PATH] . file_path_parse($output));
         }
     }
     echo json_encode($response);
 }