Welcome Guest, Not a member yet? Register   Sign In
Image Lib - Resize failure
#1

[eluser]gRoberts[/eluser]
Hi all,

Well I've found that my logic isn't wrong, its the image library, or at least it seems that way.

I have an image that is 250x350 and when I try resizing to 250x250 it remains the same size.

Any idea's?
#2

[eluser]Sarfaraz Momin[/eluser]
can u please post some code here !!!
#3

[eluser]Merolen[/eluser]
Have you tried

Code:
$config['maintain_ratio'] = FALSE;

edit: Wrote something about maintain_ratio not working. Note to self: check the dims of the image you are testing with first :red:
#4

[eluser]gRoberts[/eluser]
Sorry about that, the forums didn't notify me of any replies... i'm sure i asked it to.

It only seems to be a problem when I try resizing to 250x250.

Using both a 250x350 and 640x840 image they both remain the same size, although the code actually runs.

Code:
public function generate($source, $output, $width, $height) {
            
            $size = getimagesize($source);

            if($size[0] > $width || $size[1] > $height) {
                //echo "thumb";
                $config['image_library'] = 'GD2';
                //$config['library_path'] = '/usr/bin/X11';
                $config['source_image'] = $source;
                $config['maintain_ratio'] = TRUE;
                $config['create_thumb'] = false;
                $config['new_image'] = $output;
                $config['quality'] = 100;
                $config['width'] = (int)$width;
                $config['height'] = (int)$height;
                
                $this->base->image_lib->initialize($config);
                if(!$this->base->image_lib->resize())
                    die($this->base->image_lib->display_errors());
            } else
                copy($source, $output);
            
        }

Thanks
#5

[eluser]xwero[/eluser]
I think the problem happens when you call your function several times. The configuration options are not cleared when you use the initialize method.

Try this
Code:
public function generate($source, $output, $width, $height) {
            
            $size = getimagesize($source);

            if($size[0] > $width || $size[1] > $height) {
                //echo "thumb";
                $config['image_library'] = 'GD2';
                //$config['library_path'] = '/usr/bin/X11';
                $config['source_image'] = $source;
                $config['maintain_ratio'] = TRUE;
                $config['create_thumb'] = false;
                $config['new_image'] = $output;
                $config['quality'] = 100;
                $config['width'] = (int)$width;
                $config['height'] = (int)$height;
                
                $this->base->image_lib->clear(); // added
                $this->base->image_lib->initialize($config);
                if(!$this->base->image_lib->resize())
                    die($this->base->image_lib->display_errors());
            } else
                copy($source, $output);
            
        }

ps : you don't need to do the check to see if the image is actually bigger than the maximum dimensions. The image_lib does it for you.
#6

[eluser]gRoberts[/eluser]
I've done what you've suggested and unfortunately it didn't work Sad

As for the checking of dimensions, if the code checks, why are 16x16 images being resized up to the dimensions I pass to the code?

lol I've uploaded some pixel icons and they look nasty when resized to 800x600

Thanks all the same, any other idea's would be gratefully appreciated!
#7

[eluser]xwero[/eluser]
The check if the image needs to be resized or not is my mistake, sorry. I've probably seen it in a modified image_lib.

to check if the right width and height is set when initialize method is called you can do
Code:
$this->base->image_lib->initialize($config);
echo $this->base->image_lib->width.'*'.$this->base->image_lib->heigth;
#8

[eluser]Merolen[/eluser]
Have you checked all parameters in
Code:
if($size[0] > $width || $size[1] > $height) {
?

From what I can see if you pass a 50x50 image and set 800x600 as new size the if should work just fine Confusedhut: But from what you describe it seems to me that it goes inside the if even though it shouldn't, right? Should any of the vars in the if be cast to int? I would just put a lot of echoes inside the if and comment out the actual resizing to see that all the right vars are passed. Just throwing out some suggestions Smile

Just another thing, if you want have less code you can remove settings from the config array that has the same default value as you pass. Like maintain_ratio and create_thumb. If you don't set the quality the default value is 90. I tried with different sizes and a quality of 100 makes the image size in bytes bigger than the original :-S But if disk space isn't an issue, of course no problem having the image quality at 100 Smile
#9

[eluser]gRoberts[/eluser]
Well you've proven there is certainly an issue:

When trying to resize an image that is 640x480 to

100x100
250x250
800x600

I get the following from the echo you gave me:

100*75
250*188

Which means the image SHOULD be resized to those sizes, but the 250x188 remains 640x480.

I've var_dumped both the getimagesize results and the parameters and they are both integers.

It only seems to be an issue on the 250x250 call. The script doesn't die with any errors so I can only assume that its an CI issue?

Thanks all of you!
#10

[eluser]gRoberts[/eluser]
So you got any other suggestions? This is doing my head in.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB