Set the config details in array , like we set height and width to 50 * 50 , We are using inbuilt image library gd2.
// Configuration $config['image_library'] = 'gd2'; $config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg"; $config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg"; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 50; $config['height'] = 50;Load the Image library along with above configuration
// Load the Library
$this->load->library('image_lib', $config);
Call the resize function
// resize image
$this->image_lib->resize();
// handle if there is any problem
if ( ! $this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
resize() function resize the image file and create new image file in specified folder. You will get errors "$this->image_lib->display_errors()", if there is any problem while image manipulation.
function imageResize50X50($imgName){
$img_path = realpath("img")."\\images\\uploaded\\".$imgName.".jpeg";
// Configuration
$config['image_library'] = 'gd2';
$config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg";
$config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg";
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
// Load the Library
$this->load->library('image_lib', $config);
// resize image
$this->image_lib->resize();
// handle if there is any problem
if ( ! $this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
}
Hi I am Yashwant founder of www.technicalkeeda.com, Purpose of this website to share the programming knowledge in the form post , blogs and articles.