我有不同尺寸的图像(小于 200x200 像素)我希望它们是 200x200 像素,方法是添加具有给定颜色的空白空间(例如白色)。我尝试使用裁剪库裁剪它们: http: //codeigniter.com/user_guide/libraries/image_lib.html 我不工作。这是我没有成功使用的一些代码:
$config = Array(
'image_library' => 'gd2',
'source_image' => '/path/to/my/image.jpg',
'new_image' => '/path/to/my/small/image.jpg',
'thumb_marker' => '',
'create_thumb' => TRUE,
'maintain_ratio' => TRUE,
'width' => '200',
'height' => '200'
);
$this->load->library('image_lib', $config);
if (!$this->image_lib->resize())
{
$this->session->set_flashdata('message_error', $this->image_lib->display_errors());
redirect('/mon_controller', 'location');
}
$config['source_image'] = '/path/to/my/small/image.jpg';
$config['x_axis'] = '200';
$config['y_axis'] = '200';
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
$this->session->set_flashdata('message_error', $this->image_lib->display_errors());
redirect('/my_controller', 'location');
}
编辑:我认为 lib 符合我的需求: http: //www.matmoo.com/digital-dribble/codeigniter/image_moo/