For resizing image using Qimage component in cakephp first we have to download Qimage plugin after downloading Qimage plugin we have to put it into App/Controller/Component .
Then we have to do all this in our controller.
class UploadsController extends AppController {
public function add(){
if ($this->request->is('post')) {
$this->Upload->create();
if ($this->request->data['Upload']['photo']!='' && is_array($this->request->data['Upload']['photo'])) {
$imgData = array();
$imgData['file'] = $this->request->data['Upload']['photo'];
$imgData['name']=$this->data['Upload']['photo']['name'];
$imgData['path'] = WWW_ROOT . '' . '/images/'; // path where the image will we copied
$user_image = $this->Qimage->copy($imgData); //Qimage copy function
// Qimage resizing function,
$this->Qimage->resize(array('height' => 80, 'width' => 80,
'file' => $imgData['path'].$user_image,
'output' => WWW_ROOT. '/images/thumbnail/' // path where the image will we uploaded after resizing
)
);
}
else{
$user_image = "";
}
}
In above code firstly we are copying our image with the help of $this->Qimage->copy(); function in our webroot/images folder after copying we are resizing image with the help of $this->Qimage->resize(); function and then storing it in webroot/images/thumbnail folder.
0 Comment(s)