CI等比缩放图片
本帖最后由 smartweb 于 2011-3-8 07:48 编辑长或宽超出600就会自动等比缩小,如果小于600不会放大,我不知道'image_lib'怎写,我的代码如下,但图片被放大了。
$this->load->library('image_lib');
$config['image_library'] = 'gd2';//(必须)设置图像库
$config['source_image'] = $paths.'/'.$realname;//(必须)设置原始图像的名字/路径
$config['dynamic_output'] = FALSE;//决定新图像的生成是要写入硬盘还是动态的存在
$config['quality'] = '100%';//设置图像的品质。品质越高,图像文件越大
$config['new_image'] =$paths.'/'.$realname;//设置图像的目标名/路径。
$config['width'] = 600;//(必须)设置你想要得图像宽度。
$config['height'] = 600;//(必须)设置你想要得图像高度
$config['create_thumb'] = TRUE;//让图像处理函数产生一个预览图像(将_thumb插入文件扩展名之前)
$config['thumb_marker'] = '';//指定预览图像的标示。它将在被插入文件扩展名之前。例如,mypic.jpg 将会变成 mypic_thumb.jpg
$config['maintain_ratio'] = TRUE;//维持比例
$config['master_dim'] = 'auto';//auto, width, height 指定主轴线
$this->image_lib->initialize($config);
if (!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}else{
//echo "成功的";
} 上传大图就缩放,上传小图不缩放 $size = GetImageSize($paths.'/'.$realname);
if ( $size >800)
$config['width'] = 800;//(必须)设置你想要得图像宽度。
if ( $size >800)
$config['height'] = 800;//(必须)设置你想要得图像高度 我上传没做判断
我直接在显示的img标签里给他定义了style,max-width:800px. IE6下max-width是不支持的... 我在之前已经写出解决办法了。
$size = GetImageSize($paths.'/'.$realname);
if ( $size >800)
$config['width'] = 800;//(必须)设置你想要得图像宽度。
if ( $size >800)
$config['height'] = 800;//(必须)设置你想要得图像高度 用一个好的类对上传的图片进行缩放
页:
[1]