我正在尝试创建用户上传的图片的两个缩略图。我重复了两次代码,对第二个缩略图进行了一些配置更改,但我只创建了第一个缩略图而第二个缩略图没有创建。这是代码:
//First Thumbnail
$conf['image_library'] = 'gd2';
$conf['source_image'] = "images/photos/123.jpg";
$conf['create_thumb'] = TRUE;
$conf['thumb_marker'] = "_1";
$conf['maintain_ratio'] = true;
$conf['width'] = 150;
$conf['height'] = 150;
$this->load->library('image_lib', $conf);
$this->image_lib->resize();
//Second smaller Thumbnail
$conf2['image_library'] = 'gd2';
$conf2['source_image'] = "images/photos/123.jpg";
$conf2['create_thumb'] = TRUE;
$conf2['thumb_marker'] = "_2";
$conf2['maintain_ratio'] = true;
$conf2['width'] = 50;
$conf2['height'] = 50;
$this->load->library('image_lib', $conf2);
$this->image_lib->resize();
由于某种原因,第二部分根本不起作用,第一部分和第二部分一起运作良好。我想我不应该在同一个地方加载两次库。我该怎么做才能解决这个问题?
答案 0 :(得分:4)
你需要清除它们之间的库,使用它:
$this->image_lib->clear();
如果清除和重新加载不起作用,您可以尝试用初始化函数替换第二个库加载,而初始化函数由于某种原因未在ci_documentation中引用:
$this->image_lib->clear();
$this->image_lib->initialize($conf2);