我在想codeigniter图像类是否有内置或自动SKIP创建拇指 如果源图像宽度/高度小于您设置的拇指宽度/高度。
如果没有,该怎么处理?
我已完成缩略图生成,但如果我上传宽度:200px高度:200px图像和 我的拇指设置是宽度:400px高度:400px拇指仍将创建并制作拇指 看起来很糟糕。
编辑
$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();
}
答案 0 :(得分: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();
答案 1 :(得分: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);