在codeigniter中调整图像950 * 950的大小 [英] resize image 950*950 in codeigniter
问题描述
我在发布此问题时犹豫不决,因为我在这里看到了很多问题,但是所有答案都行不通。
I hesitated on posting this question cause I saw dozens of them here, but all the answers didn't work.
所以,我有这个工作代码。它会上传图片并获取缩略图。
So, I have this working code. It uploads picture and getting thumbnails.
我允许用户上传950 * 950图片。我想调整这些图片的大小以适合我的显示页面。
I allow users to upload a 950*950 pictures. I want to resize those pics to fit in my show page.
因此,这是调整大小的一部分:
So, here is part of the resize:
$id=uniqid();
$folder = $this->getDir($id);
$dir=FCPATH.'upload/biz_photos/'.$folder.'/';
if(!is_dir($dir)) {
mkdirs($dir);
}
//handle img
$des_file=$dir.$id.'.jpg';
$thumb_file=$dir.$id.'.thumb.jpg';
$info=getimagesize($org_file);
if($info[0] <= 300) {
copy($org_file,$dir.$id.'.jpg');
}
else
{
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
$config['source_image']=$org_file;
$config['new_image'] = $des_file;
$config['overwrite']= true;
$config['maintain_ratio'] =true;
$config['width'] = 600;
$config['height'] = floor(($info[1]/$info[0])*600);
$this->image_lib->initialize($config);
$this->image_lib->resize();
// handle if there is any problem
if ( ! $this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
}
就像我进行测试,然后上传950 * 950,然后检查上传的图片,其大小仍为原始图片的
。无需调整大小
Like when I test it, and upload a 950*950, and then check the uploaded image, the size still the original one. No resizing
推荐答案
几个小时后我确实发现了问题。因此,我有一个缩略图功能,我将原始图片传递给了它,而不是将新图片传递给了它(已缩放的图片)。
I did find the problem after few hours. So, I have a thumbnail function and I was passing to it the original picture instead of passing it the new picture (the sized picture).
谢谢
这篇关于在codeigniter中调整图像950 * 950的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!