Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on "Qimage" component to resize image in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 635
    Comment on it

    Hi Reader's,
    Welcome to FindNerd,today we are going to discuss Qimage component to resize image in CakePHP.

    If we are developing a web application in CakePHP then, sometimes we have to upload image for user profile . When a user upload image then image size is very large then we have to resize the image and save in a folder for showing user profile image.

    For the resizing image we can use "Qimage" component. So for that we have to download Qimage component plugin and after downloading plugin we have to put it into App/Controller/Component.

    You can see below code for better understand that how Qimage "Qimage" component copy the image and then resize the image.

    <?php
       class UploadsController extends AppController {
        public function UploadImage(){
          if ($this->request->is('post')){
            $this->Upload->create();
            if($this->request->data['Upload']['photo']!='' && is_array($this->request->data['Upload']['photo'])){
            $imagedetail = array();//here create a array
            $imagedetail['file'] = $this->request->data['Upload']['photo'];
            $imagedetail['name']=$this->data['Upload']['photo']['name'];
            $imagedetail['path'] = WWW_ROOT . '' . '/images/'; // where put the  path where image will we copied
            $user_image = $this->Qimage->copy($imagedetail); //here call Qimage copy function
            //here call Qimage resizing function,
            $this->Qimage->resize(array('height' => 80, 'width' => 80,
            'file' => $imagedetail['path'].$user_image,
            'output' => WWW_ROOT. '/images/thumbnail/' // path where the image will we uploaded after resizing
            )
            );
            }else{
                $user_image = "";
              }
          } 
        } 
    ?>

    In above code we are using $this->Qimage->copy() function for  copying image in our given path "webroot/images" folder and after that we are using $this->Qimage->resize() function for resizing image and also storing the image in "webroot/images/thumbnail" folder.

    I hope this blog will help you for resizing image in your CakePHP web application.

 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: