Codeigniter 图像压缩不起作用
Codeigniter image compression not working
我想在我的网站上上传大图片。我想减少那些使用 codeigniter 的人的大小。所以我正在做这个代码
function upload_image($data) {
$config['upload_path'] = './temp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('image')) {
$error = array('error' => $this->upload->display_errors());
pre($error);
} else {
$config = array();
$data = array('upload_data' => $this->upload->data());
$config['image_library'] = 'gd';
$config['source_image'] = './temp/' . $data['upload_data']['file_name'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['quality'] = 50;
$config['new_image'] = './temp/' . $data['upload_data']['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
pre($data);
}
}
但是图像没有被压缩。原始尺寸和上传尺寸相同。我哪里错了?
可能存在错误。检查错误:
if (!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
注意:使用gd2作为库(默认值为gd2):
$config['image_library'] = 'gd2';
我想在我的网站上上传大图片。我想减少那些使用 codeigniter 的人的大小。所以我正在做这个代码
function upload_image($data) {
$config['upload_path'] = './temp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('image')) {
$error = array('error' => $this->upload->display_errors());
pre($error);
} else {
$config = array();
$data = array('upload_data' => $this->upload->data());
$config['image_library'] = 'gd';
$config['source_image'] = './temp/' . $data['upload_data']['file_name'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['quality'] = 50;
$config['new_image'] = './temp/' . $data['upload_data']['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
pre($data);
}
}
但是图像没有被压缩。原始尺寸和上传尺寸相同。我哪里错了?
可能存在错误。检查错误:
if (!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
注意:使用gd2作为库(默认值为gd2):
$config['image_library'] = 'gd2';