sreelatha
sreelatha

Reputation:

create thumbnails using for loop

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

Upvotes: 0

Views: 640

Answers (2)

dado
dado

Reputation: 11

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();
}

Upvotes: 1

Matthew Rapati
Matthew Rapati

Reputation: 5686

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_guide/libraries/image_lib.html

Upvotes: 0

Related Questions