0

我正在使用以下代码,但即使$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();
4

2 回答 2

0

试试 new_image 标签:

$config['new_image'] = '/path/to/new_image.jpg';
于 2013-07-22T05:59:59.990 回答
-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);
于 2013-07-22T06:07:18.580 回答