コード例 #1
0
 /**
  * 头像裁剪
  * @return json json数据
  */
 public function crop()
 {
     $src = './Uploads/' . $_REQUEST['picName'];
     $des = './Uploads/crop_' . $_REQUEST['picName'];
     import('ORG.Util.Image.ThinkImage');
     $thinkImage = new ThinkImage();
     $thinkImage->open($src);
     $src_w = $thinkImage->width();
     $src_h = $thinkImage->height();
     $des_x = $_REQUEST['x1'] / $_REQUEST['scale'];
     $des_y = $_REQUEST['y1'] / $_REQUEST['scale'];
     $thinkImage->crop($_REQUEST['w'] / $_REQUEST['scale'], $_REQUEST['h'] / $_REQUEST['scale'], $des_x, $des_y)->save($des);
     $table = M("Head_img");
     $cnt = $table->count();
     if ($cnt > 0) {
         $data['id'] = 1;
         $data['name'] = 'crop_' . $_REQUEST['picName'];
         $data['add_time'] = time();
         $table->save($data);
     } else {
         $data['name'] = 'crop_' . $_REQUEST['picName'];
         $data['add_time'] = time();
         $table->add($data);
     }
     $jsonData['status'] = true;
     $jsonData['msg'] = '保存成功';
     $this->ajaxReturn($jsonData);
 }