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

2 回答 2

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();
于 2013-01-17T14:11:38.950 回答
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);          
于 2013-03-13T19:38:51.307 回答