Welcome Guest, Not a member yet? Register   Sign In
Upload and resize image problem.
#7

You have to use like this.


$this->load->library('image_lib');
foreach($results as $row) {
    $config['image_library'] = 'gd2';
    $config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width']     = 75;
    $config['height']   = 50;

    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
}

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


Image Resize Codeigniter Configuration

You need to do simple configuration to resize images, set the configurations properties like image_library, source_image,create_thumb etc width, height as 50 * 50, For that we are going to use inbuilt image library gd2.

// Configuration
 $config['image_library'] = 'gd2';
 $config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg";
 $config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg";
 $config['create_thumb'] = TRUE;
 $config['maintain_ratio'] = TRUE;
 $config['width'] = 50;
 $config['height'] = 50;

Load library After Configuration
$this->load->library('image_lib', $config);

Call the resize function
 // resize image
 $this->image_lib->resize();
 // handle if there is any problem
 if ( ! $this->image_lib->resize()){
  echo $this->image_lib->display_errors();
 }

 // resize image
 $this->image_lib->resize();
 // handle if there is any problem
 if ( ! $this->image_lib->resize()){
  echo $this->image_lib->display_errors();
 }

resize() function resize the image file and create new image file in specified folder. You will get errors "$this->image_lib->display_errors()", if there is any problem while image manipulation.

function imageResize50X50($imgName){
 $img_path =  realpath("img")."\\images\\uploaded\\".$imgName.".jpeg";
 
 // Configuration
 $config['image_library'] = 'gd2';
 $config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg";
 $config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg";
 $config['create_thumb'] = TRUE;
 $config['maintain_ratio'] = TRUE;
 $config['width'] = 50;
 $config['height'] = 50;

 // Load the Library
 $this->load->library('image_lib', $config);
 
 // resize image
 $this->image_lib->resize();
 // handle if there is any problem
 if ( ! $this->image_lib->resize()){
  echo $this->image_lib->display_errors();
 }
}

Hope this will help you.
Reply


Messages In This Thread
Upload and resize image problem. - by HarrysR - 09-08-2018, 12:50 PM
RE: Upload and resize image problem. - by HarrysR - 09-08-2018, 05:04 PM
RE: Upload and resize image problem. - by HarrysR - 09-09-2018, 10:55 AM
RE: Upload and resize image problem. - by Gurutechnolabs - 09-25-2018, 04:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB