Welcome Guest, Not a member yet? Register   Sign In
Upload image --> resize and create thumb
#1

[eluser]hsl[/eluser]
Hello,

I'm trying to upload an image. So far it works.
Now with the uploaded image i want to resize it to a new directory and make a thumb at the same time.
So this is what i do:
Code:
public function img_resize($upload,$post)
    {    
        $newpath = dirname(FCPATH).'/assets/shop/'.$post['title'].$upload['file_ext'];
        
        $config['image_library'] = 'gd2';
        $config['source_image']    = $upload['full_path'];
        $config['new_image'] = $newpath;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 480;
        $config['height']    = 480;
        
        
        $this->load->library('image_lib', $config);
        
        if ( ! $this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }
        
        $this->make_thumb($newpath);

        //remove temp_image here
    }

    public function make_thumb($path)
    {
        $config['image_library'] = 'gd2';
        $config['source_image']    = $path;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 150;
        $config['height']    = 150;

        $this->load->library('image_lib', $config);

        if ( ! $this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }
    }

The second function doesn't work and there doesn't seem to be a way to
do it in one image resize action.

This is what is in my controller:
Code:
$config_upload['upload_path'] = './assets/temp/';
$config_upload['allowed_types'] = 'gif|jpg|png';
$config_upload['max_size']    = '5000';
$config_upload['encrypt_name'] = TRUE;

$this->load->library('upload', $config_upload);

if (!$this->upload->do_upload())
   {
     $upload = $this->upload->display_errors();
   }    
else
   {
     $upload = $this->upload->data();
   }
$this->hsl_shop->img_resize($upload,$_POST);

How would you guys solve this?

Regards,

HSL


Messages In This Thread
Upload image --> resize and create thumb - by El Forum - 09-20-2008, 09:32 AM
Upload image --> resize and create thumb - by El Forum - 09-20-2008, 10:08 AM
Upload image --> resize and create thumb - by El Forum - 09-20-2008, 02:03 PM
Upload image --> resize and create thumb - by El Forum - 09-20-2008, 05:11 PM
Upload image --> resize and create thumb - by El Forum - 09-21-2008, 12:31 AM
Upload image --> resize and create thumb - by El Forum - 09-21-2008, 05:36 AM
Upload image --> resize and create thumb - by El Forum - 09-21-2008, 05:41 AM
Upload image --> resize and create thumb - by El Forum - 09-21-2008, 08:53 AM
Upload image --> resize and create thumb - by El Forum - 04-25-2010, 08:35 PM
Upload image --> resize and create thumb - by El Forum - 01-02-2011, 06:31 PM
Upload image --> resize and create thumb - by El Forum - 01-02-2011, 06:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB