2013-01-17 128 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);