嗨,根据ci文档,您可以使用image_lib调整图像大小,有些选项建议我们可以从该图像创建其他缩略图
create_thumb FALSE TRUE/FALSE (boolean) Tells the image processing function to create a thumb. R
thumb_marker _thumb None Specifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpg R
所以这是我的代码
$config_manip = array(
'image_library' => 'gd2',
'source_image' => "./uploads/avatar/tmp/{$this->input->post('new_val')}",
'new_image' => "./uploads/avatar/{$this->input->post('new_val')}",
'maintain_ratio'=> TRUE ,
'create_thumb' => TRUE ,
'thumb_marker' => '_thumb' ,
'width' => 150,
'height' => 150
);
$this->load->library('image_lib', $config_manip);
$this->image_lib->resize();
我会假设此代码调整我的图像大小,并创建一个缩略图,但我只获得一个具有指定尺寸的图像和_tump后缀
我也尝试添加此代码手动创建第二个图像,但它仍然无法工作,我只得到一个图像
$this->image_lib->clear();
$config_manip['new_image'] =
"./uploads/avatar/thumbnail_{$this->input->post('new_val')}";
$config_manip['width'] = 30 ;
$config_manip['height'] = 30 ;
$this->load->library('image_lib', $config_manip);
$this->image_lib->resize();
解决方法:
似乎路径是代码中的问题.我修改并测试了自己的工作原理.
public function do_resize()
{
$filename = $this->input->post('new_val');
$source_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/tmp/' . $filename;
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/';
$config_manip = array(
'image_library' => 'gd2',
'source_image' => $source_path,
'new_image' => $target_path,
'maintain_ratio' => TRUE,
'create_thumb' => TRUE,
'thumb_marker' => '_thumb',
'width' => 150,
'height' => 150
);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
// clear //
$this->image_lib->clear();
}
希望这对你有所帮助.谢谢!!