[英]How to resize image height and width in php codeigniter
public function resize() { $config['width'] = $this->input->post('width'); $config['height'] = $this->input->post('height'); $config['maintain_ratio'] = TRUE; $config['source_image'] = './uploads1/book.jpg'; $config['new_image'] = './uploads1/book_new.jpg'; $this->image_lib->initialize($config); $resize = $this->image_lib->resize(); }
How to resize image height and width in php codeigniter, only height is not resizing properly but width i am getting如何在 php codeigniter 中调整图像高度和宽度,只有高度没有正确调整大小,但我得到了宽度
$this->load->library('image_lib');
if (!empty($_FILES['advert_image'])) {
$filename = substr(md5(time()), 0, 28) . strrchr($_FILES['advert_image']['name'], '.');
$config['upload_path'] = 'public/events/images/';
$config['allowed_types'] = 'jpg|jpeg|png|JPG|JPEG|PNG|BMP|bmp|gif|GIF';
$config['file_name'] = $filename;
$config['is_image'] = true;
$this->load->library('upload', $config);
$this->upload->initialize($config);
//$this->upload->do_upload('advert_image');
//start resize image
if (!$this->upload->do_upload('advert_image')) {
echo "error" . count;
} else {
$image_data = $this->upload->data();
$configer = array(
'image_library' => 'gd2',
'source_image' => $image_data['full_path'],
'maintain_ratio' => TRUE,
'width' => 480,
'height' => 480,
);
$this->image_lib->clear();
$this->image_lib->initialize($configer);
$this->image_lib->resize();
}
//end resize
$profile_pic = isset($filename) ? $filename : "";
}
You have to initialize the library to use it after setting config values:您必须在设置配置值后初始化库才能使用它:
$this->load->library('image_lib', $config);
Be sure the input values of height is not empty too!确保高度的输入值也不为空!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.