如何使用Codeigniter中的for循环从解压缩的图像文件夹创建缩略图?
答案 0 :(得分:1)
没了 这会更好
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();
}
答案 1 :(得分:0)
加载目录助手:
$this->load->helper('directory');
映射目录:
$images = directory_map('./directoryRelativeToIndexDotPhp/');
现在你是$ images中的一组文件,为image_lib类设置一个configure数组并循环遍历它们,调整图像大小:
$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();
}
未经测试,但这应该会给你一个良好的开端。您可能希望在调整大小之前检查文件是否是实际图像。
查看图像处理库http://codeigniter.com/user_guide/libraries/image_lib.html
的文档