Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to crop image using Qimage component in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 852
    Comment on it

    For cropping 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    uploaded
                
                $user_image = $this->Qimage->copy($imgData); //Qimage copy function
    
                 $this->Qimage->crop(array('w' => 300,'h' => 300,'x' => 100,'y' => 100,
                                           'file' =>$imgData['path'].$user_image,
                                           'output' => WWW_ROOT. '/images/thumbnail' ));
                     
                 // Qimage cropping function, here w is reffered for width ,h for height,x for x-axis,and y for y-axis. 
    
            }
          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 cropping image with the help of $this->Qimage->crop(); function and then storing it in webroot/images/thumbnail folder.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: