Phalcon 图像调整大小

Phalcon image resize

在使用 GD Adapter 的 phal im 中,我的代码示例是这样的。它正确调整图像大小但未按预期调整。如果图像的宽度超过 458px,我想调整图像的大小,在这种情况下它工作正常,但如果低于 457px,它不应该调整大小它应该保持原样。但是我的脚本总是调整任何大小的图像有什么问题吗?请!

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

您必须添加关于图像宽度的条件。类似于:

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