2

I am using the following code but don't know why thumbnails are not created.

//UPLOAD IMAGE
    //some $config vars for image
    $config['upload_path'] = './images/models';
    $config['allowed_types'] = 'gif|jpg|jpeg|png|tif';
    $config['max_size'] = '0';
    $config['remove_spaces'] = true;
    $config['overwrite'] = false;
    $config['max_width'] = '0';
    $config['max_height'] = '0';

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

    //upload main image
    if(!$this->upload->do_upload('photo')){
        $e = $this->upload->display_errors();
        print_r($e);
    }

    $image = $this->upload->data();

    //print '<pre>';
    //print_r($image); exit;

    if($image['file_name']){
        $data['photo']  = "images/models/". $image['file_name'];
        $data['raw' ]   = $image['raw_name'];
        $data['ext']    = $image['file_ext'];
    }


    //create new image
    $config0['image_library'] = 'gd2';
    $config0['source_image'] = $image['full_path'];
    $config0['new_image'] = "images/models/"."front". $image['file_name']; // you can assign your image name and location
    $config0['maintain_ratio'] = FALSE;
    $config0['width'] = 320;
    $config0['height'] = 270;

    $this->load->library('image_lib', $config0);
    if ( ! $this->image_lib->resize())
    {
    echo $this->image_lib->display_errors();
    }

    //end of new image



    $config3['image_library'] = 'gd2';
    $config3['source_image'] = $image['full_path'];
    $config3['new_image'] = "images/models/"."main". $image['file_name'];
    $config3['maintain_ratio'] = FALSE;
    $config3['width'] = 800;
    $config3['height'] = 600;

    $this->load->library('image_lib', $config3);
    $this->image_lib->initialize($config3);
    $this->image_lib->resize();



    $config4['image_library'] = 'gd2';
    $config4['source_image'] = $image['full_path'];
    $config4['new_image'] = "images/models/"."third". $image['file_name'];
    $config4['maintain_ratio'] = FALSE;
    $config4['width'] = 185;
    $config4['height'] = 125;

    $this->load->library('image_lib', $config4);
    $this->image_lib->initialize($config4);
    $this->image_lib->resize();


    //thumbnail creation start
    $config1['image_library'] = 'gd2';
    $config1['source_image'] = $image['full_path'];
    $config1['create_thumb'] = TRUE;
    $config1['maintain_ratio'] = FALSE;
    $config1['width'] = 185;
    $config1['height'] = 125;

    $this->load->library('image_lib', $config1);
    $this->image_lib->initialize($config1);
    if ( ! $this->image_lib->resize())
    {
    echo $this->image_lib->display_errors();
    }

    //THUMBNAIL ENDS
1
  • is there a reason you are loading the library 4 times instead of just re-initializing? Commented Aug 15, 2011 at 12:49

4 Answers 4

2

Try this. It is almost like yours. Write errors in the comments.

//UPLOAD IMAGE
//some $config vars for image
$config['upload_path'] = './images/models';
$config['allowed_types'] = 'gif|jpg|jpeg|png|tif';
$config['max_size'] = '0';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$config['max_width'] = '0';
$config['max_height'] = '0';

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

//upload main image
if(!$this->upload->do_upload('photo')){
    $e = $this->upload->display_errors();
    print_r($e);
}else{
    $image = $this->upload->data();

    //print '<pre>';
    //print_r($image); exit;

    if($image['file_name']){
        $data['photo']  = "images/models/". $image['file_name'];
        $data['raw' ]   = $image['raw_name'];
        $data['ext']    = $image['file_ext'];
    }

    $config1['source_image'] = $image['full_path'];
    $config1['new_image'] = "images/models/"."front". $image['file_name']; // you can assign your image name and location
    $config1['maintain_ratio'] = FALSE;
    $config1['width'] = 320;
    $config1['height'] = 270;

    $this->load->library('image_lib', $config1);
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
        return;
    }

    $config1['new_image'] = "images/models/"."main". $image['file_name'];
    $config1['width'] = 800;
    $config1['height'] = 600;

    $this->image_lib->clear();
    $this->image_lib->initialize($config1);
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
        return;
    }



    $config1['new_image'] = "images/models/"."third". $image['file_name'];
    $config1['width'] = 185;
    $config1['height'] = 125;

    $this->image_lib->clear();
    $this->image_lib->initialize($config1);
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
        return;
    }


    //thumbnail creation start
    unset($config1['new_image']);
    $config1['create_thumb'] = TRUE;

    $this->image_lib->clear();
    $this->image_lib->initialize($config1);
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
        return;
    }
    echo "Ok";
}

//THUMBNAIL ENDS
Sign up to request clarification or add additional context in comments.

Comments

2

The way the Image Manipulation class was designed, is that if you want to use it more than once within the same script, you have to run:

$this->image_lib->clear();

between the images being processed.

This clears all the previous settings, and gives you a clean slate for the next crop/rotate/watermark/whatever...

2 Comments

That didn't help either, not after creating new image and create thumbnail
image_lib->clear() does NOT set all settings back to their defaults (which is what we might expect it to do). So, you might have to reset some defaults with each config. I can't remember all the details, but i know this issue leads to unexpected results when doing multiple image functions.
0

The most common problem with server side file system writing operations are lack of permissions. At a glance the code looks good to me, can you check that your thumbmail directories are writeable, try with chmod-ing the directories 777

1 Comment

directory is writeable, the create thumbnail works when i move the thumbnail create block just below file upload ( above creating another images) but it doesn't work when i place create thumbnail block at bottom, pls help
0

This problem might be due to mismatch in path of the image create. Try using FCPATH constant before url. That might help..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.