我已經解決了我的問題。我不得不重新調整圖像大小然後剪裁。無論如何,如果你有比這更好的建議,那麼它有點漫長的過程。
我的代碼:
//Resize Image
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = './assets/original/'.$image_name;
$config['new_image'] = './assets/banner/'.$image_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['master_dim']= 'width';
$config['quality'] = '100';
$config['width'] = 1260;
$config['height']= 645;
$this->image_lib->initialize($config);
$this->image_lib->resize();
// Crop Image
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = './assets/banner/'.$image_name;
$config['new_image'] = './assets/banner/'.$image_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['quality'] = '100';
$config['x_axis'] = 0;
$config['y_axis'] = 0;
$config['width'] = 1260;
$config['height']= 645;
$this->image_lib->initialize($config);
$this->image_lib->crop();
此外,作物中心的形象,你可以添加此 \t列表($ current_width,$ current_height)=和getimagesize($ source_image); $ config ['x_axis'] =($ current_width/2) - (225/2); $ config ['y_axis'] =($ current_height/2) - (225/2); – Nadeshwaran