CodeIgniter Forums
Image Library - Resize and Thumbnail - 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 Library - Resize and Thumbnail (/showthread.php?tid=3414)



Image Library - Resize and Thumbnail - El Forum - 09-29-2007

[eluser]ELRafael[/eluser]
Greetings... i have this situation:

An user'll post an image, and the app needs to resize to the layout width/height...

so is my code:
Code:
//Redimensiona a foto
    $config1['image_library']  = 'GD2';
    $config1['source_image']   = "./public/$photo";
    $config1['create_thumb']   = TRUE;
    $config1['maintain_ratio'] = TRUE;
    $config1['width']        = 80;
    $config1['height']       = 80;
    $this->load->library('image_lib', $config1);

    //Cria o thumb
    $this->image_lib->resize();

Ok, this works fine :-P
Original file: 1.jpg
Thumb: 1_thumb.jpg

But, if the user puts an image larger, i want to resize the ORIGINAL.

So what i do
Code:
//Redimensiona a original
    $config1['create_thumb']    = FALSE;
    $config1['width']             = 480;
    $config1['height']         = 300;
    $this->load->library('image_lib', $config1);
    $this->image_lib->resize();

But the orginal image still the same dimensions! >:-(

I didn't put all the values from $config1 in the second resize method call cause i think that gets the last values.

this is the hole code
Code:
//Redimensiona a foto
    $config1['image_library']  = 'GD2';
    $config1['source_image']   = "./public/$photo";
    $config1['create_thumb']   = TRUE;
    $config1['maintain_ratio'] = TRUE;
    $config1['width']       = 80;
    $config1['height']        = 80;
    $this->load->library('image_lib', $config1);
                    
    //Cria o thumb
    $this->image_lib->resize();
                    
    //Redimensiona a original
    $config1['create_thumb']    = FALSE;
    $config1['width']         = 480;
    $config1['height']         = 300;
    $this->load->library('image_lib', $config1);
    $this->image_lib->resize();



Image Library - Resize and Thumbnail - El Forum - 09-29-2007

[eluser]gunter[/eluser]
don´t use this if you have more than one image to convert... (it will work only for the first - so in your example with the two conversion only the first one will processed - because after the second config array the image lib is already loaded, and the config will not be initialized...
Code:
$this->load->library('image_lib', $config1); // no no no! don´t use this!!!

instead use this:
Code:
$this->load->library('image_lib');
$this->image_lib->initialize($config);  //whenever you change the config array



Image Library - Resize and Thumbnail - El Forum - 10-02-2007

[eluser]feri_soft[/eluser]
Now it creates the right number of imgs but the tumb is still not resized and the watermark is not on the original but on the thumb. Please help on these issues! Thanks!


Image Library - Resize and Thumbnail - El Forum - 10-02-2007

[eluser]ELRafael[/eluser]
[quote author="feri_soft" date="1191370232"]Now it creates the right number of imgs but the tumb is still not resized and the watermark is not on the original but on the thumb. Please help on these issues! Thanks![/quote]

Code:
$config1['width']         = 480;
$config1['height']         = 300;

did you set the new size and watermarks? put that old code here again, otherwiser people can get lost, don't you think?


Image Library - Resize and Thumbnail - El Forum - 10-02-2007

[eluser]feri_soft[/eluser]
Here is the code now:

Code:
if(!empty($_FILES)){
                $num_files = count($_FILES);
                $config['upload_path'] = 'S:/xampp/htdocs/asdasdasd';
                $config['allowed_types'] = 'jpg';
                $config['max_width'] = '800';
                $config['max_height'] = '600';
                $this->load->library('upload', $config);
                for($i = 1; $i <= $num_files; $i++){
                    $field_name = 'file_' . $i;
                    $this->upload->do_upload($field_name);
                    $upload_data = $this->upload->data();
                    $new_file = $upload_data['file_path'] . $product_id . '_' . $i . '.jpg';
                    rename($upload_data['full_path'], $new_file);
                    
                    $config1['image_library'] = 'GD';
                    $config1['source_image'] = $new_file;
                    $config1['create_thumb'] = TRUE;
                    $config1['maintain_ratio'] = FALSE;
                    $config1['width'] = '80';
                    $config1['height'] = '60';
                    $config1['wm_type'] = 'overlay';
                    $config1['wm_vrt_alignment'] = 'bottom';
                    $config1['wm_hor_alignment'] = 'right';
                    $config1['wm_overlay_path'] = 'S:/xampp/htdocs/asdasdasd/w.png';

                    $this->load->library('image_lib');
$this->image_lib->initialize($config1);

                    $this->image_lib->resize();
                    $this->image_lib->watermark();
                }
                
            }

Remember i need the following functionality a user uploads some images, then a thumb of each image is created and then the ORIGINAL not the thumb is watermarked. You can try the following code now and see what happens. My thumb gets watermarked and its not the right size!? Thanks!


Image Library - Resize and Thumbnail - El Forum - 10-03-2007

[eluser]ELRafael[/eluser]
[quote author="feri_soft" date="1191409004"]Here is the code now:

Code:
if(!empty($_FILES)){
                $num_files = count($_FILES);
                $config['upload_path'] = 'S:/xampp/htdocs/asdasdasd';
                $config['allowed_types'] = 'jpg';
                $config['max_width'] = '800';
                $config['max_height'] = '600';
                $this->load->library('upload', $config);
                for($i = 1; $i <= $num_files; $i++){
                    $field_name = 'file_' . $i;
                    $this->upload->do_upload($field_name);
                    $upload_data = $this->upload->data();
                    $new_file = $upload_data['file_path'] . $product_id . '_' . $i . '.jpg';
                    rename($upload_data['full_path'], $new_file);
                    
                    $config1['image_library'] = 'GD';
                    $config1['source_image'] = $new_file;
                    $config1['create_thumb'] = TRUE;
                    $config1['maintain_ratio'] = FALSE;
                    $config1['width'] = '80';
                    $config1['height'] = '60';
                    $config1['wm_type'] = 'overlay';
                    $config1['wm_vrt_alignment'] = 'bottom';
                    $config1['wm_hor_alignment'] = 'right';
                    $config1['wm_overlay_path'] = 'S:/xampp/htdocs/asdasdasd/w.png';

                    $this->load->library('image_lib');
$this->image_lib->initialize($config1);

                    $this->image_lib->resize();
                    $this->image_lib->watermark();
                }
                
            }

Remember i need the following functionality a user uploads some images, then a thumb of each image is created and then the ORIGINAL not the thumb is watermarked. You can try the following code now and see what happens. My thumb gets watermarked and its not the right size!? Thanks![/quote]

Code:
$config1['source_image'] = $new_file;
Code:
$this->image_lib->watermark();

Did you see? For sure the app will aply the watermark in the source_image... Probably the $new_file is your thumb....

Ah, other thing. The resize method is not exactly to dimensions (w/h). Will try the closer value...


Image Library - Resize and Thumbnail - El Forum - 10-03-2007

[eluser]gunter[/eluser]
I think I have it...

I believe, your picture is being resized correctly to the thumb
but then is still this active: $config1['create_thumb'] = TRUE;
and the watermark function will overwrite the thumb with the original picture (but watermarked...)
and now the 'thumb' has the dimension of the original file

so after the resize do this:
Code:
$config1['create_thumb'] = false;
//and initalize it again!
and then you can apply the watermark...
(at least in my theory...) :coolhmm:


Image Library - Resize and Thumbnail - El Forum - 10-03-2007

[eluser]feri_soft[/eluser]
WEll ok but if a change the condig array i should re-initialize the image lib right?


Image Library - Resize and Thumbnail - El Forum - 10-03-2007

[eluser]gunter[/eluser]
don´t ask!
do it!!! :grrr:


Image Library - Resize and Thumbnail - El Forum - 10-03-2007

[eluser]feri_soft[/eluser]
Tried it but now i have a thumb with right size and again watermarked ... just watermark is on the wrong place.