THINKPHP+JS zoom image screenshot implementation

  • 2020-03-31 20:30:39
  • OfStack

Author: Yang xinqi

The original link: (link: http://www.cnblogs.com/scotoma/archive/2010/03/05/1679477.html)

A big brother of TP forum tonight added me, said also encountered this aspect of the problem, ha ha! Think of a lot of things have come across, should we share it? Actually oneself of a lot of things are others that come, take at the network use at the network! Only if we share more, can we improve!

implementation

Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image zoom save class processing image -- save captured image -- update database -- jump

 

Take a few screenshots

< img border = 0 SRC = "http://files.jb51.net/upload/2010-3/20100307131624825.jpg" >

 

The following is a screenshot of the example

< img border = 0 SRC = "http://files.jb51.net/upload/2010-3/20100307131624550.jpg" >

 

< img border = 0 SRC = "http://files.jb51.net/upload/2010-3/20100307131624507.jpg" >

 

< img border = 0 SRC = "http://files.jb51.net/upload/2010-3/20100307131624960.jpg" >

The main implementation code


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(); 
} 
} 


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 '<img src="'.__ROOT__.'/' . $path . $large . '" />'; 
// update database 
} 
else 
{ 
// error reporting 
} 
}

The source code download address: (link: http://xiazai.jb51.net/201003/yuanma/cutimg.rar) other to perfect themselves, please visit http://www.thinkphp.cn to download operation need TP framework, and then download the expansion pack, because use the Upload class!


Related articles: