我正在使用以下代码,但即使$this->image_lib->resize()
返回true也无法调整图像大小,不知道出了什么问题:
if(file_exists($_SERVER['DOCUMENT_ROOT']."/uploads/avatars/".str_replace('_','-',$image)))
{
$config['source_image'] = $_SERVER['DOCUMENT_ROOT']."/uploads/avatars/".str_replace('_','-',$image);
}
else if (!file_exists("./uploads/avatars/".$image) || $image=="")
{
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/avatars/photo.jpg';
}
else
{
$config['source_image'] = $_SERVER['DOCUMENT_ROOT']."/uploads/avatars/".$image;
}
$config['image_library'] = 'gd2';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['dynamic_output'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
答案 0 :(得分:0)
尝试使用new_image标记:
$config['new_image'] = '/path/to/new_image.jpg';
答案 1 :(得分:-1)
最好在CodeIgniter中使用SimpleImage.php作为帮助程序
$source=base_url().'/uploads/avatars/photo.jpg';
$image = new SimpleImage();
$image->load($source);
$image->resize(600,400);
$image->save($name_and_location);