Author: Yang Xinqi
Original link: http://www.cnblogs.com/scotoma/archive/2010/03/05/1679477.html
Tonight, a big brother from the TP forum added me, saying that he also encountered this problem, haha! Come to think of it, I have encountered many things, should I share it? In fact, many of my things came from others, taken from the Internet and used on the Internet! Only by sharing more can we improve!
How to implement it
Upload pictures -- Save and display pictures -- JS gets thumbnail parameters -- Submit location parameters -- Image scaling and saving class processing pictures -- Save captured pictures -- Update database -- Jump
The last few screenshots
The following is an example screenshot
Main implementation code
Copy code The code is as follows:
public function cutimg()
{
$result = $this->upload('temp');
if (!is_array($result))
{
$this->redirect('index');
}
else
{
$this->assign('imgurl', '__ROOT__/' . C('ATTACHDIR') . '/temp/' . $result[0]['savename' ]);
$this->assign('imgname', $result[0]['savename']);
$this->display();
}
}
Copy code The code is as follows:
public function setavatar()
{
if (!empty($_REQUEST['cut_pos']))
{
// import('ORG.Util.ImageResize');
require('ImageResize.class.php');
$imgresize = new ImageResize();
// use the full path
$url = C('ATTACHDIR') . '/temp/' . trim($_POST['imgname']);
$imgresize->load($url);
dump($url);
$posary = explode(',', $_REQUEST['cut_pos']);
foreach($posary as $ k => $v)
$posary[$k] = intval($v);
if ($posary[2] > 0 && $posary[3] > 0) $imgresize->resize($posary[2], $posary[3]);
dump($posary);
// create filename rule
$uico = time( ) . '.jpg';
dump($uico);
$path = C('AVATAR');
// save 120*120 image
$imgresize->cut(120 , 120, intval($posary[0]), intval($posary[1]));
$large = 'l_' . $uico;
$imgresize->save($path . $large );
echo '
';
// update database
}
else
{
// error reporting
}
}
Source code download address: Click to download other ones and improve them yourself. Please visit the TP framework required to run Download http://www.thinkphp.cn, and then download the expansion pack, because the Upload class is used!
http://www.bkjia.com/PHPjc/321362.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321362.htmlTechArticleAuthor: Yang Xinqi Original link: http://www.cnblogs.com/scotoma/archive/2010/03/ 05/1679477.html A big brother from the TP forum added me tonight, saying that he also encountered this problem, haha...