I want to resize an image from the original size of an image file using Codeigniter. When I upload it into the database, I want to resize before upload file. How can I resize image and insert into the database in Codeigniter?
I am following this code:
<?php $path = $_FILES['product_image']['name']; $ext = pathinfo($path, PATHINFO_EXTENSION); $image = time() ."product_list_img".".".$ext; $product_image = $image; $config['upload_path'] = './assets/images/'; $config['allowed_types'] = 'gif|jpg|jpeg|png'; $config['file_name'] = $image; $this->load->library('upload', $config); $this->upload->do_upload('product_image'); ?>
For resize image in codeigniter apply image_lib library and use resize function.
$this->load->library('image_lib', $config); $this->image_lib->resize();
For example:
<?php $path = $_FILES['product_image']['name']; $ext = pathinfo($path, PATHINFO_EXTENSION); $image = time() ."product_list_img".".".$ext; $product_image = $image; $config['upload_path'] = './assets/backend/images/product_image/'; $config['allowed_types'] = 'gif|jpg|jpeg|png'; $config['file_name'] = $image; $this->load->library('upload', $config); $this->upload->do_upload('product_image'); // Image Resize $config['image_library'] = 'gd2'; $config['source_image'] = './assets/images/'.$product_image; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 500; $config['height'] = 800; $this->load->library('image_lib', $config); $this->image_lib->resize(); ?>
Question and answer is powered by AnsPress.io