unsets
并使用第二个配置。
// Retrieve the data from the upload
$data = $this->upload->data();
//Re-size the large image and re-save it
$config['image_library'] = 'gd2';
$config['source_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/'.$file_name.''.$data['file_ext'];
$config['new_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/';
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'auto';
$config['width'] = 600;
$config['height'] = 516;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
else
{
$this->image_lib->crop();
echo 'Image Resized!';
}
//Create a thumbnail for the image
$config['image_library'] = 'gd2';
$config['source_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/'.$file_name.''.$data['file_ext'];
$config['new_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/thumbnails/';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 120;
$config['height'] = 120;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
else
{
echo 'Image Thumbnail Created!';
}
因此,它会重新调整图像大小,然后应该缩略图像。
答案 0 :(得分:4)
您可以使用library提供的初始化方法,因此您每次都可以调用它而不是加载库:
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/'.$file_name.''.$data['file_ext'];
$config['new_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/';
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'auto';
$config['width'] = 600;
$config['height'] = 516;
$this->image_lib->initialize($config);
...
$config['image_library'] = 'gd2';
$config['source_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/'.$file_name.''.$data['file_ext'];
$config['new_image'] = $this->config->item('upload_path').''.$this->aauth->get_user_id().'/thumbnails/';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 120;
$config['height'] = 120;
$this->image_lib->initialize($config);