CodeIgniter Forums
Image Resizing doesn't work [Solved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Image Resizing doesn't work [Solved] (/showthread.php?tid=37604)



Image Resizing doesn't work [Solved] - El Forum - 01-14-2011

[eluser]catiaresende[/eluser]
Hi,

I need some help because I don't understand why the code doesn't resize uploaded images.
Actually I'm using GalleryCMS, so, I have the code to upload them, to create the thumbnail and, after that I added this code to resize:

Code:
function resize($fileName, $ext) {
        $mainimage = '../galeria/fotos/'.$fileName.'.'.$ext;
        
        list($width, $height, $type, $attr) = getimagesize($mainimage);
        
                
        $config['image_library'] = 'GD2';
        $config['source_image'] = $mainimage;
        $config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 400;
        $config['height'] = 400;

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

Below the code to upload, I have this too:

Code:
$uploadImage = '../galeria/fotos/'.$newname;
            write_file($uploadImage, $file);
            $this->_createThumbnail($md5Date, $ext, $thumbWidth, $thumbHeight, $newname, $thumbname);
            $this->resize($md5Date, $ext, $thumbWidth, $thumbHeight, $newname, $thumbname);

        } else {
            $this->load->view('gallery_view');
        }

Any idea?
Greetings.


Image Resizing doesn't work [Solved] - El Forum - 01-14-2011

[eluser]Cristian Gilè[/eluser]
Is upload process performed with success?
Is the source_image setting correct?

Why do you call two times the resize method? It's not necessary!

Code:
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize())
echo $this->image_lib->display_errors();

Cristian Gilè


Image Resizing doesn't work [Solved] - El Forum - 01-14-2011

[eluser]catiaresende[/eluser]
Cristian, thank you for your reply.


The upload process and the thumbnail creation works fine. There's no problem with that, so I assume that the source it's ok, because it's the same.

To write the resize process, I followed these instructions: http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html.

Have you have any idea about what's (not) happening?


Image Resizing doesn't work [Solved] - El Forum - 01-14-2011

[eluser]catiaresende[/eluser]
Hello again,

Luckily I managed to do the resize. What I did was add the code for the resize function inside the thumbnail creation, instead of creating a new function.
The final code looked like this:

Code:
$config['image_library'] = 'GD2';
        $config['source_image'] = $mainimage;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = true;
        $config['master_dim'] = 'width';
        $config['width'] = $new_width;
        $config['height'] = $new_height;
        $config['quality'] = '100%';

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

        //Resize
        $config['create_thumb'] = FALSE;
        $config['width']  = 500;
        $config['height']  = 500;
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
        
        $config['image_library'] = 'GD2';
        $config['source_image'] = $t;
        $config['create_thumb'] = FALSE;
        $config['width'] = $final_width;
        $config['height'] = $final_height;
        $config['x_axis'] = $to_crop_left;
        $config['y_axis'] = $to_crop_top;
        $config['maintain_ratio'] = false;

        $this->image_lib->initialize($config);
        if(!$this->image_lib->crop()) {
            echo $this->image_lib->display_errors();
        } else {
            $this->gallery_tbl->insertImage($_POST['id'], $newname, $thumbname);


Thanks again.