php - Image resize not working in CodeIgniter 3 -
i developing web application. in application, uploading image server , resize it. uploaded server successfully. when resize image, not resizing image. not throwing error well.
this image file upload model
class file_helper extends ci_model{ function __construct() { parent::__construct(); $this->load->library('image_lib'); } function generaterandomfilename() { $rand = rand(10000,99999); $file_name = time().$rand; return time().$rand; } function uploadimage() { $name = $this->generaterandomfilename(); $config['upload_path'] = './'.upload_folder.'/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['file_name'] = $name; $this->load->library('upload', $config); if ( !$this->upload->do_upload('userfile')) { return false; } else { $data = $this->upload->data(); $data['virtual_path'] = upload_folder."/".$name.".".$data['file_ext']; return $data; } } function resizeimage($path) { $config['image_library'] = 'gd2'; $config['source_image'] = '/'.$path; $config['create_thumb'] = true; $config['maintain_ratio'] = true; $config['width'] = 300; $config['height'] = 50; $this->load->library('image_lib', $config); if ( ! $this->image_lib->resize()) { print_r($this->image_lib->display_errors()); } else{ echo "ok"; } } }
as can see in model print out "ok" on success , print_r error in failure. path passed "uploads/23344545.png". resize function print out "ok", image not resized. wrong code?
you need resize image while uploading
function uploadimage() { $name = $this->generaterandomfilename(); $config['upload_path'] = './'.upload_folder.'/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['file_name'] = $name; $config['width'] = 300; $config['height'] = 50; $this->load->library('upload', $config); if ( !$this->upload->do_upload('userfile')) { return false; } else { $data = $this->upload->data(); $data['virtual_path'] = upload_folder."/".$name.".".$data['file_ext']; return $data; } }
Comments
Post a Comment