views:

210

answers:

2

How to create Thumbnails from an unzipped image folder using for loop in Codeigniter?

A: 

Load the directory helper:

$this->load->helper('directory');

Map the directory:

$images = directory_map('./directoryRelativeToIndexDotPhp/');

Now you an array of files in $images, set up a configure array for the image_lib class and loop through them, resizing the images:

$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
foreach ($images AS $file) {
    $config['source_image'] = $file;
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
}

Not tested but this should give you a good start. You will probably want to check if the files are actually images before resizing.

Check out the documentation on the image manipulation library http://codeigniter.com/user%5Fguide/libraries/image%5Flib.html

mrinject
A: 

nope this would be better

config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$this->load->library('image_lib', $config);
foreach ($images AS $file) {
    $config['source_image'] = $file;
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
}
dado