Welcome Guest, Not a member yet? Register   Sign In
resizing image twice
#1

[eluser]Unknown[/eluser]
hello there ,

I have a problem in resizing an image twice to different sizes

i upload an image which size is 300px X 300px

i want to resize it to 200px X 200px , and make a thumbnail with 32px X 32px dimensions

it resizes it perfectly to 200 x 200 and then says

Quote:Your server does not support the GD function required to process this type of image.

when resizing to 32px X 32px


this is the code i use


Code:
// resize                
                $config2['image_library'] = 'gd2';
                $config2['source_image'] = $upload_data["full_path"];
                $config2['create_thumb'] = FALSE;
                $config2['maintain_ratio'] = TRUE;
                $config2['width'] = 200;
                $config2['height'] = 200;
                $this->load->library('image_lib', $config2);
                
                $this->image_lib->resize();                  
                // resize              
                
                $this->image_lib->clear();

                // make thumb              
                $config2['image_library'] = 'gd2';
                $config2['source_image'] = $upload_data["full_path"];
                $config2['new_image'] = $upload_data["file_path"]."thumb_".$upload_data["raw_name"].$upload_data["file_ext"];                
                $config2['maintain_ratio'] = TRUE;
                $config2['width'] = 32;
                $config2['height'] = 32;      
                $this->load->library('image_lib', $config2);                
                
                $this->image_lib->resize();                  
                // make thumb
#2

[eluser]TheFuzzy0ne[/eluser]
Loading the library a second time will just be ignored by CodeIgniter, so essentially, you're using the same configuration twice, since the second is completely ignored. You'd be better off using $this->image_lib->intitialize().

You might also find that you have problems if you use the same array twice for two different configurations. When reusing an array, all of the old values still exist. When you set the array for the second time, you're overriding what's already in the first, but if you didn't set a specific index the second time around, the original value will still remain. The easiest way to get around that is to simply reinitialise the array the second time you use it, or to not bother with a variable at all.

Code:
$this->load->library('image_lib');

$this->image_lib->initialize(array(
    'source_image' => $upload_data['full_path'],
    'width' => 200,
    'height' => 200,
));

$this->image_lib->resize();

$this->image_lib->clear();

$this->image_lib->initialize(array(
    'source_image' => $upload_data['full_path'],
    'new_image' => $upload_data['file_path'].'thumb_'.$upload_data['raw_name'].$upload_data['file_ext'],
    'width' => 32,
    'height' => 32,
));        

$this->image_lib->resize();

I've also stripped out a couple of options, since the defaults are exactly what you defined in your config array.




Theme © iAndrew 2016 - Forum software by © MyBB