• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Image resizing problem

#1
[eluser]Zorancho[/eluser]
Hi all, i am having troubles using the Image library from CodeIgniter.
I need to upload an image within an admin panel through an upload form where the admin can choose 3 types of size 468X60, 120X60 and 120X25, so according to which size he chooses, i have to resize the image, but after trying few times the image ends up being modified to 127X127 PX.
Here is the code i am using:
Code:
//Function to upload the image, it works well. It is in MY_Controller class
function upload_image($path, $image_name, $up_file)
{
    $config['upload_path'] = './'.$path;
    $config['allowed_types'] = 'jpg';
    $config['max_size']    = '125';
    $config['max_width']  = '800';
    $config['max_height']  = '600';
    $config['file_name'] = $image_name;
    $config['overwrite'] = TRUE;
    $this->load->library('upload');
    $this->upload->initialize($config);
    if($this->upload->do_upload($up_file))
    {
        return $this->upload->data();
    }
    else
    {
        return FALSE;
    }
}

//This function is situated in MY_Controller, so i can use it in all controllers.
function modify_image($path, $image_name, $thumb = FALSE, $height = 100, $width = 100)
{
    $config['image_library'] = 'gd2';
    $config['source_image'] = './'.$path.'/'.$image_name;
    if($thumb)
    {
        $config['create_thumb'] = TRUE;
    }
    else
    {
        $config['create_thumb'] = FALSE;
    }
    $config['maintain_ratio'] = FALSE;
    $config['width'] = $width;
    $config['height'] = $height;
    $this->load->library('image_lib');
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    if($this->image_lib->resize())
    {
        return TRUE;
    }
    return FALSE;
}

I call the function like this:
Code:
//I upload the photo and on return i get the upload data:
$image = $this->upload_image('upload_images/', $banner['company_id'].'_banner', 'ban_img');

if($image != FALSE)
{
    //This never resize the image to the 468X60 pixels
    $this->modify_image('upload_images/', $image['file_name'], FALSE, 468, 60)
}
I know i am doing something wrong, but don't know where, any help is highly appreciated.
Thank you in advance
Zoran


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.