Welcome Guest, Not a member yet? Register   Sign In
crop() does nothing when cropping 100%
#1

[eluser]splufdaddy[/eluser]
I have an interface that allows users to set a crop area on an image. If they select the whole image, the crop() function doesn't do anything. This is a problem for me because my crop function is set up to perform the crop and save it as a new image, and the new image is not made.

I noticed that a change was made to Image_lib.php from 1.5.4 to 1.6.1 .

This code:
Code:
// If the target width/height match the source then it's pointless to crop, right?
            if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height)
            {
                // We'll return true so the user thinks the process succeeded.
                // It'll be our little secret...
    
                return TRUE;
            }

was changed to this:
Code:
// If the target width/height match the source then it's pointless to crop, right?
            // So if dynamic output isn't on, then we'll return true so the user thinks
            // the process succeeded. It'll be our little secret...

            if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height AND $this->dynamic_output !== TRUE)
            {
                return TRUE;
            }
Would it make sense to also check before we secretly return true that the config does not specify a new file name ($config['new_image'])?

My workaround right now is to copy the original file to the new destination, and then perform the crop. If a crop happens, then the new file is overwritten. If the user selected 100% to crop, then the crop() does nothing, but the image has already been moved.
#2

[eluser]splufdaddy[/eluser]
Any thoughts on this? I'd love to be able to rely on crop to move my image to a new location, even if the crop is set to 100% of the image.
#3

[eluser]splufdaddy[/eluser]
Sorry for the second bump, but I'd love to get my change incorporated into CI.

I changed line 460 of Image_lib.php from this:
Code:
if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height AND $this->dynamic_output !== TRUE)
to this:
Code:
if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height AND $this->dynamic_output !== TRUE AND $this->full_src_path == $this->full_dst_path)

and crop works.

I'm not sure if you'll want to add some additional logic, because now if we're trying to crop an image to a new location and the crop width or height is larger than the original width or height, the crop will continue.




Theme © iAndrew 2016 - Forum software by © MyBB