2016-04-07 13 views
0

phal imでGDアダプターを使用し、私のコードサンプルはこのようです。そのリサイズ画像は正常には正しく表示されません。私はその幅が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()); 
     } 
    } 
} 

答えて

3

画像の幅に関する条件を追加する必要があります。次のようなもの:

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

Thnx!その作業...ありがとう! – munaz

関連する問題