public function crop() { $img = $_GET['img']; $src = C('ATTACHDIR') . $_GET['src']; $avatardir = C('AVATARDIR') . $this->uid; $avatarsmall = $this->uid . '_avatar_small.jpg'; $avatarmiddle = $this->uid . '_avatar_middle.jpg'; $avatarbig = $this->uid . '_avatar_big.jpg'; @mkdir($avatardir, 0777, true); $image = new Image($src); $scale = $image->width() / 300; $img['w'] = $img['w'] * $scale; $img['h'] = $img['h'] * $scale; $img['x'] = $img['x'] * $scale; $img['y'] = $img['y'] * $scale; $image->crop($img['w'], $img['h'], $img['x'], $img['y'], 150, 150); $image->save($avatardir . '/' . $avatarbig); $image = new Image($src); $image->crop($img['w'], $img['h'], $img['x'], $img['y'], 50, 50); $image->save($avatardir . '/' . $avatarmiddle); $image = new Image($src); $image->crop($img['w'], $img['h'], $img['x'], $img['y'], 30, 30); $image->save($avatardir . '/' . $avatarsmall); $this->t('member')->where(array('uid' => $this->uid))->update(array('avatarstatus' => 1)); $this->showAjaxReturn('success'); }
public function setavatar() { $upload = new \Core\UploadImage(); if ($filedata = $upload->saveImage()) { $filedata['uid'] = $this->uid; $filedata['username'] = $this->username; $filedata['uptime'] = time(); $filedata['photoid'] = $this->t('photo')->insert($filedata, true); //裁剪图片 $sourceImg = C('ATTACHDIR') . $filedata['attachment']; $avatardir = C('AVATARDIR') . $this->uid; $avatarsmall = $this->uid . '_avatar_small.jpg'; $avatarmiddle = $this->uid . '_avatar_middle.jpg'; $avatarbig = $this->uid . '_avatar_big.jpg'; @mkdir($avatardir, 0777, true); $image = new Image($sourceImg); if ($image->width() > $image->height()) { $w = $image->height(); $x = ($image->width() - $image->height()) / 2; $y = 0; } else { $w = $image->width(); $x = 0; $y = ($image->height() - $image->width()) / 2; } $image->crop($w, $w, $x, $y, 150, 150); $image->save($avatardir . '/' . $avatarbig); $image = new Image($sourceImg); $image->crop($w, $w, $x, $y, 50, 50); $image->save($avatardir . '/' . $avatarmiddle); $image = new Image($sourceImg); $image->crop($w, $w, $x, $y, 30, 30); $image->save($avatardir . '/' . $avatarsmall); $this->t('member')->where(array('uid' => $this->uid))->update(array('avatarstatus' => 1)); $this->showAppData(array('url' => image($filedata['attachment']))); } else { $this->showAppError(-1, 'upload error', array('errno' => $upload->error)); } }