使用codeigniter调整图像大小


Image resize with codeigniter

我一直在寻找一些教程或帮助我解决这个问题的东西,我正在开发一个网站,用户可以在该网站上发布提供房间的广告,当他们发布广告时,他们可以添加一些照片。我想调整照片的大小并降低一些质量,这样它们就不会变得太大。问题是有时用户会插入奇怪的分辨率,所以我想做一些类似css背景大小:cover属性的事情。调整照片大小,使较小的一侧适合并裁剪其余部分。

ImageMoo库将完全按照您的意愿运行。功能强大且易于使用

官方网站

CI论坛线程

试试这个:首先加载图像库:

$this->load->library('image_lib');

然后给出像这样的图像配置

$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();//You can also pass the width,height params through this function

就是这样。这对你有帮助吗?

WideImage

http://wideimage.sourceforge.net/

http://getsparks.org/packages/wideimage-ci/versions/HEAD/show

基本用法

// output to browser in JPG format with quality set to 80%.
$this->wideimage->load('image.png')->resize(90, 90)->output('jpg', 80);

Image MOO是一个出色的库,可以实时完成图像操作。。。。

例如,要将上传的图像调整到特定的路径,你只需要执行这个

function example_callback_after_upload($uploader_response,$field_info,                                 $files_to_upload)
{
$this->load->library('image_moo');
//Is only one file uploaded so it ok to use it with $uploader_response[0].
$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name; 
$this->image_moo->load($file_uploaded)->resize(800,600)->save($file_uploaded,true);
return true;
}

有关更多详细信息,请参阅:image-moo库希望这能有所帮助!!

同样,测试这个代码。

$this->image_moo->load(FCPATH.'/upload/'.$image)->resize(750,450,TRUE)->save(FCPATH.'/upload/'.'750-450-124545cd.png', $overwrite=false);