/** * 头像裁剪 * @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); }
/** * * @图片处理 * @$i 打开的图片 * @width 保存的宽度 * @height 保存的高度 * @save 保存的图片名称 * @作者 shop猫 * @版权 宁波天发网络 * @官网 http://www.tifaweb.com http://www.dswjcms.com */ protected function imageProcessing($i, $width, $height, $save) { import('ORG.Util.Image.ThinkImage'); $img = new ThinkImage(); $img->open($i)->crop($img->width(), $img->height(), 0, 0, $width, $height)->save($save); }