0

I am using the code to resize the image if the file size is greater than 1MB,am using this in the model function,but it returns false.Whats wrong here.

if($_FILES[$name]['size']/(1024)>1024){

    $upload_data = $this->upload->data();

    $config2['image_library'] = 'ImageMagick';  
    $config2['source_image'] = $upload_data["file_path"];  
    $config2['create_thumb'] = TRUE;  
    $config2['maintain_ratio'] = TRUE;  
    $config2['quality'] = '60%';  
    $config2['width'] = 200;  
    $config2['height'] = 200;  
    //$config2['new_image'] = $upload_data["file_name"];  

    $this->load->library('image_lib', $config2); 
    $this->image_lib->clear();
    $this->image_lib->initialize($config2);

    var_dump($this->image_lib->resize());

}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Jibin
  • 424
  • 2
  • 4
  • 15

1 Answers1

0

You shouldn't load image_lib in if. Try to use code below

$this->load->library('image_lib');

if($_FILES[$name]['size']/(1024)>1024){

    $upload_data = $this->upload->data();

    $config2['image_library'] = 'ImageMagick';  
    $config2['source_image'] = $upload_data["file_path"];  
    $config2['create_thumb'] = TRUE;  
    $config2['maintain_ratio'] = TRUE;  
    $config2['quality'] = '60%';  
    $config2['width'] = 200;  
    $config2['height'] = 200;  
    //$config2['new_image'] = $upload_data["file_name"];  

    $this->image_lib->clear();
    $this->image_lib->initialize($config2);

    var_dump($this->image_lib->resize());

}
Happy Son
  • 81
  • 4