Welcome Guest, Not a member yet? Register   Sign In
Help with image_lib->resize() ?
#1

[eluser]chefnelone[/eluser]
Hello
I have this function which upload a image and then if the image is bigger than 800X600 it is resized.
It uploads the image but the resize isn't working. I can't see where is my mistake:
It doesn't show any error
Code:
function upload_image(){
        $config['upload_path'] = './uploads/image/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '5000';
        $config['max_width']  = '4000';
        $config['max_height']  = '4000';
        
        $this->load->library('upload', $config);
            
        if ( ! $this->upload->do_upload() )
        {
            $error = array('error' => $this->upload->display_errors());

        }    
        else
        {
            //GET THE DATA OF THE UPLOADED IMAGE
            $data = $this->upload->data();
        
            if($data['image_width'] >= 800 || $data['image_height'] >= 600  ){    
                            
                $config2['image_library'] = 'GD2';
                $config2['source_image'] = './uploads/image/'.$data['file_name'];
                $config2['quality'] = 100;
                $config2['maintain_ratio'] = FALSE;
                $config2['width'] = 800;
                $config2['height'] = 600;
                $config2['quality'] = 70;
                    
    
                $this->load->library('image_lib', $config2);
                
                if(! $this->image_lib->resize()){
                    $error2 = $this->image_lib->display_errors();
                }
            }
        }
    }

any help??
#2

[eluser]pisio[/eluser]
if(! $this->image_lib->resize()){
$error2 = $this->image_lib->display_errors();
pritn_r($error2);
}
#3

[eluser]chefnelone[/eluser]
[quote author="pisio" date="1282012086"]if(! $this->image_lib->resize()){
$error2 = $this->image_lib->display_errors();
pritn_r($error2);
}[/quote]
Thanks got it working!

edit: no at all....
#4

[eluser]chefnelone[/eluser]
It works but only with some values. ...Just wondering if the Image Lib has a bug or the new patch for the Upload lib has affected it?

First problem is that if the value of $config2['width'] is bigger than 630, let say 640, then it fails with any image I try to upload.

Second problem is: if $config2['width'] = 630; it works fine with a image of 1024px X 777px (600Kb). But it fails again if I upload a image of 1200px X 900px(700Kb).

With fails I mean it just stops in the line $this->image_lib->resize(), no $errors, nothing, the function just stops.

In any case the image is uploaded correctly. The problem is just with resize().

I've been around this for hours... it's driving me crazy. I really appreciate any help

My php.ini is set to allows to upload up to 32mb: upload_max_filesize = 32M

Code:
function upload_image(){
        $config['upload_path'] = './uploads/image/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '5000';
        $config['max_width']  = '4000';
        $config['max_height']  = '4000';
        
        $this->load->library('upload', $config);
            
        if ( ! $this->upload->do_upload() )
        {
            $error = array('error' => $this->upload->display_errors());

        }    
        else
        {
            //GET THE DATA OF THE UPLOADED IMAGE
            $data = $this->upload->data();
        
            if($data['image_width'] >= 900 || $data['image_height'] >= 700  ){    
                            
                $config2['image_library'] = 'GD2';
                $config2['source_image'] = './uploads/image/'.$data['file_name'];
                $config2['quality'] = 100;
                $config2['maintain_ratio'] = FALSE;
                $config2['width'] = 630; // If this value is bigger than 630 it fails
                $config2['height'] = 600;
                $config2['quality'] = 70;
                    
    
                $this->load->library('image_lib', $config2);
                
                if(! $this->image_lib->resize()){
                    $error2 = $this->image_lib->display_errors();
                    $this->firephp->log( $error2 );
                }
            }
        }
    }
#5

[eluser]Mat-Moo[/eluser]
As your using gd2 you could try my Image_moo library http://ellislab.com/forums/viewthread/161469/
#6

[eluser]Petsoukos[/eluser]
I get the same error:
Your server does not support the GD function required to process this type of image.

But the resize function runs and saves the resized image in the destination directory. I don't know why it spits out the error...

I'm autoloading the image_lib since I use it allot.
This code runs after successful upload from the form
Code:
if(!$this->upload->do_upload()){ //..

Code:
} else {
// Create Manager Thumbs
$image = $this->upload->data();
$source = './media/img_source/'.$image['orig_name'];
            
$config['source_image'] = $source;
$config['image_library'] = 'GD2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 150;
$config['new_image'] = './media/manager_thumbs/';
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);
}

I get the 2 files that I need and in their own directory... one in the source where the originals are kept and one on the thumbs folder.

I can't figure out why it spits the error since the function runs and works correctly.




Theme © iAndrew 2016 - Forum software by © MyBB