Welcome Guest, Not a member yet? Register   Sign In
I need help to resize image before uploading
#1

[eluser]DumpProgrammer[/eluser]
I have a model function that creates and upload an image and also creates a thumbnail but I do not know how to resize the initial image before its uploaded. The examples shown are just for resizing an image. Here is my current function.
Code:
$config['upload_path'] = 'uploads/';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '1000';
        $config['max_width'] = '1920';
        $config['max_height'] = '1280';
        $config['maintain_ratio'] = TRUE;
        
                    
        $this->load->library('upload', $config);
        
        if(!$this->upload->do_upload('image')) echo $this->upload->display_errors();
        else {
            $fInfo = $this->upload->data();
            $this->_createThumbnail($fInfo['file_name']);
            
            $data['image'] = mktime();
            $data['image'] .= $fInfo['file_name'];            
            $data['thumbnail'] = $fInfo['raw_name'] . '_thumb' . $fInfo['file_ext'];                
        }

    $this->db->insert('posts', $data);    
}
#2

[eluser]Twisted1919[/eluser]
1.How could you ever re-size an image before you upload it ? Does this makes sense to you ?
You process an image AFTER you have it uploded on your server .

2.Don't use Models for these tasks . Use a helper or a plugin for this .

3.Codeigniter Resizing class requires a lot of work and calculation to get a nice looking image , that's because it doesn't have an Adaptive Resizeing Method , BUT PhpThumb does ( http://phpthumb.gxdlabs.com/ )

So if i were you, i would use codeigniter upload library to upload my image , then , using phpthumb , i would resize it with desired width and height using adaptive resize method .
#3

[eluser]DumpProgrammer[/eluser]
I realise it doesnt make sense but I was just assuming someone would know that the image I want stored on my computer or server will be the resized image. I thought codeigniter can resize an image for me and also maintain the image ratio
Quote:$config['maintain_ratio'] = TRUE;
. So if the initial image that I upload can be stored on a tempfolder and then used to generate a smaller image then thats exactly what I am looking for.
#4

[eluser]DumpProgrammer[/eluser]
I am trying to use the phpthumb but there is no documentation on how to use it. I need to intergrate it into CI so I think I will put it into plugins folder. Can anyone give me a hint or direction on how I can use it to save images onto my server and also retrieve the image file and thumb file name. Thanks
#5

[eluser]Dyllon[/eluser]
[quote author="DumpProgrammer" date="1267310011"]So if the initial image that I upload can be stored on a tempfolder and then used to generate a smaller image then thats exactly what I am looking for.[/quote]

You kinda just answered your own question, upload the image to a temporary location, resize it specifying a new image name and location, and lastly unlink your temporary image.

All easily done with the CI image library




Theme © iAndrew 2016 - Forum software by © MyBB