0

I want to upload large images on my website. I want to reduce the size of those using codeigniter. So I am doing this code

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);
    }
}

But images are not being compressed. Original and uploaded size are the same. Where am I wrong?

Ali Zia
  • 3,825
  • 5
  • 29
  • 77
  • 1
    use this parameter with quality param then it will reduce the size of image $config['width'] = 75; $config['height'] = 50; – Rajat Gupta Apr 27 '17 at 07:04

1 Answers1

0

Maybe exists an error. Check for errors:

if (!$this->image_lib->resize()){
    echo $this->image_lib->display_errors();
}

Note: Use gd2 as library (default value is gd2):

$config['image_library'] = 'gd2';
Mohammad Hamedani
  • 3,304
  • 3
  • 10
  • 22