Welcome Guest, Not a member yet? Register   Sign In
Image resizing patch for image_lib
#1

[eluser]#1313[/eluser]
If you want your image_lib only resize your image if it is bigger than your 'width' and 'height' parameters and do not resize if image is smaller then you may find this piece of code useful:

Code:
if ($this->orig_width >= $this->orig_height && $this->orig_width > $this->width) {
            $quotient = $this->orig_width / $this->width;
            $this->height = ceil($this->orig_height / $quotient);
        } else if ($this->orig_height > $this->orig_width && $this->orig_height > $this->height) {
            $quotient = $this->orig_height / $this->height;
            $this->width = ceil($this->orig_width / $quotient);
        } else {
            $this->width = $this->orig_width;
            $this->height = $this->orig_height;
        }

Insert it into your libraries/Image_lib.php in image_reproportion() function at line 1266 after these lines:
Code:
if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0)
            return;
And delete or comment everything below inserted code in this function. Now it will behave as expected.

PS. Disclaimer: use at your own risk. This is a 'quick and dirty' patch which worked fine with my app (CI 1.5.4) but can possibly kill something in yours. Don't forget to backup your library if you're not sure what are you doing.
PPS. I personally think that this behavior must be the default behavior of any image resizing functuon. I was deeply shocked when i discovered that such great framework lacks this important (and very often used) functionality.




Theme © iAndrew 2016 - Forum software by © MyBB