2013-01-17 130 views
1

請不要創建縮略圖我在考慮codeigniter圖像類是否內置或自動跳過創建縮略圖 如果源圖像的寬度/高度小於拇指寬度/高度你設置。如果源圖像寬度/高度小於拇指寬度/高度

如果不是,該如何處理?

我也做了縮略圖生成,但如果我上傳寬度:200像素高度:200像素的圖像和 我的拇指設置寬度:400像素高度:400像素拇指仍然會創建,使拇指 看壞。

編輯

$config['config_here']; 
$this->load->library('image_lib', $config); 

if($arr['image_width'] <= $config['width'] && $arr['image_height'] <= $config['height'])  { 
//I don't want to resize the image BUT I want it to copy to a filename with thumb_marker 
//How to do it because I already have the $config['create_thumb'] = TRUE; at above. 
}else{ 
    $this->image_lib->resize(); 
} 
+1

我認爲你需要擴展圖像庫檢查庫的調整大小方法$ this-> orig_width> $ this-> width或height然後你ne編輯調整它的大小。它會工作 – umefarooq

+0

好吧,將嘗試它。 – vzhen

+0

@umefarooq你能再次看到我編輯的問題嗎? – vzhen

回答

1

你可以調整前檢查大小:

// get image sizes 
list($width, $height) = getimagesize($config['source_image']); 

// is wide enough? 
if (intval($width) < 400) { 
    throw new Exception("Your image's height must be equal or greater than 400px"); 
} 

// is high enough? 
if (intval($height) < 400) { 
    throw new Exception("Your image's width must be equal or greater than 400px"); 
} 

// now we can resize 
$this->image_lib->resize(); 
+0

你能再次看到我編輯的問題嗎? – vzhen

0

您可以檢查圖像尺寸操作 前試試這個

list($width, $height) = getimagesize($pathToImages); 
    if($thumbWidth > $width) 
    { 
     $new_width = $width; 
     $new_height = $height; 
    } 
    else 
    { 
     $new_width = $thumbWidth; 
     $new_height = floor($height * ($thumbWidth/$width)); 
    } 


    $config = array(
     'image_library' => 'gd2', 
     'quality' => '100%', 
     'source_image' => $pathToImages, 
     'new_image' => $pathToThumbs, 
     'maintain_ratio' => true, 
     'create_thumb' => false, 
     'width' => $new_width, 
     'height' => $new_height 
    );    
    $ci->image_lib->initialize($config);