在phal中使用GD Adapter,我的代码示例是这样的。它正确调整图像大小但不是预期的。如果它的宽度超过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());
}
}
}
答案 0 :(得分:3)
你必须添加一个关于图像宽度的条件。类似的东西:
$image = new GdAdapter('uploads/blogs/'.$imgName);
if ($image->getWidth() > 458) {
$image->resize(458,458)->crop(457,457)
}
$image->save('uploads/blogs/'.$imgName);