CodeIgniter Forums

Full Version: Image resize manipulation?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]solid9[/eluser]
I have this codes below,
I'm not sure which is better?

this one?
Code:
$result = array_unique($filenames);

    //resize images into thumb size and save it into thumbs folder

    foreach($result as $value) {
     $config['image_library'] = 'gd2';
     $config['source_image'] = '/home/xeon9/public_html/barterswapping.com/photo-product/'. $value;    
     $config['new_image'] = '/home/xeon9/public_html/barterswapping.com/thumbs/';  
      
     $config['create_thumb'] = TRUE;
     $config['maintain_ratio'] = TRUE;
     $config['width'] = 150;
     $config['height'] = 100;

    
     $this->load->library('image_lib', $config);
    
     if (!$this->image_lib->resize())
     {
         echo $this->image_lib->display_errors();
     } else {
      echo 'resize done!';  
     }
    }


or this one?
Code:
$result = array_unique($filenames);
//resize images into thumb size and save it into thumbs folder
$config['image_library'] = 'gd2';
$config['new_image'] = '/home/xeon9/public_html/barterswapping.com/thumbs/';  
      
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 100;

foreach($result as $value) {
$config['source_image'] = '/home/xeon9/public_html/barterswapping.com/photo-product/'. $value;    

$this->load->library('image_lib', $config);
  
if (!$this->image_lib->resize())
  {
      echo $this->image_lib->display_errors();
  } else {
   echo 'resize done!';  
  }
}

Thanks in advanced.

El Forum

[eluser]CroNiX[/eluser]
Code:
$result = array_unique($filenames);
$this->load->library('image_lib'); //don't load the library in a loop; once is enough
//resize images into thumb size and save it into thumbs folder
$config['image_library'] = 'gd2';
$config['new_image'] = '/home/xeon9/public_html/barterswapping.com/thumbs/';    
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 100;

foreach($result as $value)
{
  //Since you are doing this in a loop, you need to reinitialize as per the user guide
  $this->image_lib->clear();
  $config['source_image'] = '/home/xeon9/public_html/barterswapping.com/photo-product/'. $value;
  
  //Initialize with the new config for this loop
  $this->image_lib->initialize($config);
  
  if ( ! $this->image_lib->resize())
  {
    echo $this->image_lib->display_errors();
  } else {
    echo 'resize done!';  
  }
}

El Forum

[eluser]solid9[/eluser]
@cronix

Surely you are an experienced coder. Smile
Thanks again dude.