0
嗨,我想知道您是否可以幫助我,基本上我使用的是Codeigniter,我希望能夠上傳圖像並將其保存爲三個不同大小的文件夾,但它們必須適合我指定的確切尺寸沒有看到拉伸或扭曲。在Codeigniter中調整大小和裁剪效果
這是我的控制器 - 如果你能幫助我,我將不勝感激。
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$this->load->library('upload');
$this->upload->initialize($config);
if(!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('submit', $error);
}
else {
$data['upload_data'] = array('upload_data' => $this->upload->data());
$file_name = $this->upload->file_name;
list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name);
// create small size
$config['image_library'] = 'GD2';
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name;
$config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name;
$config['maintain_ratio'] = TRUE;
$config['width'] = 181;
$config['height'] = 115;
$config['master_dim'] = 'width';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if($image_width >= $config['width'] AND $image_height >= $config['height'])
{
if (!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
} else {
if(file_exists($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name))
{
list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name);
if($image_height > '115')
{
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name;
$y_axis = $image_height - 115;
$config['y_axis'] = $y_axis;
$config['x_axis'] = 181;
$this->image_lib->initialize($config);
if (!$this->image_lib->crop())
{
echo $this->image_lib->display_errors();
} else {
echo "cropped";
}
}
}
}
}