Phalcon image resize

In phal im using GD Adapter and my code sample is like this. Its resize image properly but not as expected. i want to resize image if its width more than 458px, this case its working ok but if the is lower then 457px it should not resize it should keep it as it is. but my script always resize any size of image whats the wrong? please !

if($this->request->hasFiles(true) == true)
{
    foreach ($this->request->getUploadedFiles() as $file)
    {
        #Required enable extension=php_fileinfo.dll in php.ini
        if ($this->imageCheck($file->getRealType()))
        {
            //echo $file->getName(), " ", $file->getSize(), "\n";
            $imgName = md5(uniqid(rand(), true)).strtolower(date('-dmy-').$file->getName());
            $file->moveTo('uploads/blogs/' . $imgName);
            #Resize & Crop Image
            $image = new GdAdapter('uploads/blogs/'.$imgName);
            $image->resize(458,458)->crop(457,457)->save('uploads/blogs/'.$imgName);
            $blog->bimage = $imgName;
        }
        else
        {
            $this->flashSession->error("File extension not allowed");
            return $this->response->redirect($this->router->getControllerName());
        }
    }
}

Answers 1

  • you have to add a condition about image width. Something like:

      $image = new GdAdapter('uploads/blogs/'.$imgName);
      if ($image->getWidth() > 458) {
          $image->resize(458,458)->crop(457,457)                    
      }
      $image->save('uploads/blogs/'.$imgName);
    

Related Articles