[eluser]Marcellus[/eluser]
Try to set up the majority of your $config hash outside of the foreach. Once in the foreach loop, set whichever setting you need ( $config['source_image'] = $dir.$row.... ), then call
$this->image_lib->initialize($config);
before your resize() call. So it should look something like this:
Code:
$this->load->library('image_lib');
$dir = $this->config->config['file_url'].$this->config->config['products_dir'];
$sql = "SELECT styleno FROM products WHERE front = '1' ORDER BY styleno ASC";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
$config['image_library'] = 'gd2';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 400;
$config['height'] = 400;
$config['thumb_marker'] = '_f';
foreach($query->result() as $row){
if(file_exists($dir.$row->styleno.'_f.jpg')){
unlink($dir.$row->styleno.'_f.jpg');
}
$config['source_image'] = $dir.$row->styleno.'.jpg';
$this->image_lib->initialize($config); //MUST CALL THIS METHOD
if(!$this->image_lib->resize()){
echo '<p>'.$row->styleno.' not resized</p>';
}else{
echo '<p>'.$row->styleno.'</p>';
}
$this->image_lib->clear();
}
}