我想在上传后将图像调整为两张图片。一张是大图(600*600),另一张是小图(150*150),但在这部分显示错误“$this->image_lib->resize()”即非对象上的函数 resize() 。
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form');
}
function do_upload()
{
$config_upload['upload_path'] = './uploads';
$config_upload['allowed_types'] = 'gif|jpg|png';
$config_upload['max_size'] = '5000';
$config_upload['encrypt_name'] = TRUE;
$this->load->library('upload', $config_upload);
if (!$this->upload->do_upload())
{
$upload = $this->upload->display_errors();
}
else
{
$upload = $this->upload->data();
}
$this->small_img_resize($upload);
}
public function small_img_resize($upload)
{
$newpath = "./smallimg";
$config['image_library'] = 'gd2';
$config['source_image'] = $upload['full_path'];
$config['new_image'] = $newpath;
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 150;
if ($this->image_lib->resize()) // error function resize() on a non-object
{
$this->load->library('image_lib', $config);
$this->big_img_resize($upload);
}
else
{
echo $this->image_lib->display_errors();
}
}
public function big_img_resize($upload)
{
$newpath="./bigimg";
$config['image_library'] = 'gd2';
$config['source_image'] = $upload['full_path'];
$config['new_image'] = $newpath;
$config['maintain_ratio'] = true;
$config['width'] = 600;
$config['height'] = 600;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
}
}