您好我正在使用Codigniter图像处理类来创建具有固定大小的缩略图 所以我不会先调整大小(所以当我裁剪它时,我会得到一个很大的图像和平) 然后裁剪它 调整大小工作但作物不
这是我创建的功能
function _generate_thumbnail($filename)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './project_pics/big/'.$filename;
$config['new_image'] = './project_pics/resize/'.$filename;
$config['maintain_ratio'] = TRUE;
$config['width'] = 650;
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$config['image_library'] = 'gd2';
$config['source_image'] = './project_pics/resize/'.$filename;
$config['new_image'] = './project_pics/crop/'.$filename;
$config['width'] = 650;
$config['height'] = 450;
$config['x_axis'] = 0;
$config['y_axis'] = 0;
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->crop();
}
答案 0 :(得分:1)
使用Codeigniter的image_lib
库有一些限制。你不能用这个lib一次性"resize and crop"
。
您必须在每个操作之间重新image_lib
,如下所示:
function _generate_thumbnail($filename)
{
$config1 = $config2 = array();
$config1['image_library'] = 'gd2';
$config1['source_image'] = './project_pics/big/'.$filename;
$config1['new_image'] = './project_pics/resize/'.$filename;
$config1['maintain_ratio'] = TRUE;
$config1['width'] = 650;
$this->load->library('image_lib');
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$this->image_lib->clear();
$config2['image_library'] = 'gd2';
$config2['source_image'] = './project_pics/resize/'.$filename;
$config2['new_image'] = './project_pics/crop/'.$filename;
$config2['width'] = 650;
$config2['height'] = 450;
$config2['x_axis'] = 0;
$config2['y_axis'] = 0;
$this->image_lib->initialize($config2);
$this->image_lib->crop();
}