Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation Ratio not working
#1

[eluser]Sanity11[/eluser]
Hi all,
I have a problem with the image manipulation class. To clarify this is the code:

Code:
$upload_info = array('upload' => $this->upload->data());
            
            $new_filename = explode('.', $upload_info['upload']['file_name']);
            
            $new_filename_rs = $new_filename[0] . '_rs.' . $new_filename[1];
            $new_filename_wm = $new_filename[0] . '_wm.' . $new_filename[1];
            
            $this->load->library('image_lib');
            
            $config_rs['source_image'] = './images/uploads/' . $upload_info['upload']['file_name'];
            $config_rs['maintain_ratio'] = TRUE;
            //$config_rs['master_dim'] = 'auto';
            $config_rs['width'] = 500;
            $config_rs['new_image'] = './images/uploads/' . $new_filename_rs;
            
            $this->image_lib->initialize($config_rs);
            $this->image_lib->resize();
            
            $config_rs['new_image'] = './images/uploads/' . $new_filename_wm;
            
            $this->image_lib->initialize($config_rs);
            $this->image_lib->resize();
        
            $config_wm['source_image'] = './images/uploads/' . $new_filename_wm;
            $config_wm['wm_overlay_path'] = './images/uploads/wm.png';
            $config_wm['wm_type'] = 'overlay';
            $config_wm['wm_vrt_alignment'] = 'center';
            $config_wm['wm_hor_alignment'] = 'center';
            $config_wm['dynamic_output'] = FALSE;
            $config_wm['create_thumb'] = FALSE;
        
            $this->image_lib->initialize($config_wm);
        
            $this->image_lib->watermark();
            
            $this->od_model->insert_image_data($new_filename_rs, $new_filename_wm);
            
            if (! $this->image_lib->watermark())
            {
                $upload_info = array('wm_info' => $this->image_lib->display_errors(), 'path' => $data['uploaded_images_path'] . $upload_info['upload']['file_name']);
                $this->images($upload_info);
            }
            else
            {
                //Als alles klaar is wordt de functie images aageroepen. Deze herlaadt de pagina zodat de updates zichtbaar zijn.
                $this->images($upload_info);
            }

This code does the following:
-Copy the original uploaded image with a different name and resize to a widht of 500px;
-Make another copy of the original uploaded image with a different filename and resize to a width of 500px;
-Apply a watermark to the second copy.

The aspect ratio of the first image is distorted, only the width is changed to 500, the height is still from the original image.

The second image where the watermark is applied to is correct.

It looks like in the attachment.

Does anyone know how come?
#2

[eluser]TheFuzzy0ne[/eluser]
I suspected we hadn't seen the last of this. I'm guessing that with an overlay, you need to have the overlay at the correct dimensions to begin with. I think you need to try and get it working with the text watermark again.
#3

[eluser]Sanity11[/eluser]
Hi, yeah you were right. The class has some strange config to it.

What I don't really understand is how the watermark interferes. The copies are made first, and the image with the watermark is resized correctly.
#4

[eluser]Sanity11[/eluser]
Anybody?! This is a real problem.
#5

[eluser]Sanity11[/eluser]
Hiya,

I have left out the watermarking for testing. It still gives the exact same problem. The first image is bad. The second is correct?

What I did find out is that the second image isn't changed at all. It's not resized.
#6

[eluser]TheFuzzy0ne[/eluser]
Sorry I abandoned you. I've been really busy of late and totally forgot about this problem. I regret to inform you that I still have nothing to add towards a solution. Sorry.
#7

[eluser]Sanity11[/eluser]
No problem TheFuzzy0ne, I don't expect you to help me Smile, I just hope that someone in the community with image resizing experience picks this up Smile
#8

[eluser]Unknown[/eluser]
I was having the same issue, and couldn't figure it out. Let me know if you manage to fix it.
#9

[eluser]Sanity11[/eluser]
I have been trying a lot of different settings. I give up. This looks like a bug to me.
#10

[eluser]benmanson[/eluser]
I was having a similar problem with image resizing and have found that you need to specify both height and width for the resize, then it seems to maintain the ratio fine. It will resize based on the smallest dimension but seems to maintain the ratio correctly.

If you want all your resized images to have a maximum width of 500px, just make sure your height setting is much greater than you are likely to need.

Hope that helps.
Ben




Theme © iAndrew 2016 - Forum software by © MyBB