CodeIgniter Forums
Resize only if bigger - 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: Resize only if bigger (/showthread.php?tid=23327)



Resize only if bigger - El Forum - 10-07-2009

[eluser]Kamape[/eluser]
Hi!

I want to resize an image ONLY if the image is bigger than the constraints. Is this possible? As it is now the small pictures get's resized bigger and that's not the purpose for me.

Thanks in advance


Resize only if bigger - El Forum - 10-07-2009

[eluser]Kamape[/eluser]
Nevermind, used getimagesize() instead to decide operation.

But if there's anything built in CI please post this.


Resize only if bigger - El Forum - 10-07-2009

[eluser]stuart_g[/eluser]
I don't use the CI functions for image resizing, but instead just upload the fullsize images and then display using phpThumb and let that handle the resizing on my behalf. It has the option to only resize if bigger than constraints.

http://phpthumb.sourceforge.net/


Resize only if bigger - El Forum - 10-07-2009

[eluser]Kamape[/eluser]
Thanks for the suggestion, but I'm currently uploading an image, then resizing if bigger than 640x480 AND creating a thumb. Theese two I'm binary saving into the database and then deleting the files onto disk.

Maybe phpThumb can accomplish reading like that anyway, I'll better try that of for my next project.

Thanks!


Resize only if bigger - El Forum - 10-07-2009

[eluser]pistolPete[/eluser]
[quote author="Kamape" date="1254930406"]Nevermind, used getimagesize() instead to decide operation.

But if there's anything built in CI please post this.[/quote]

If you use the upload class, you automatically get the image dimensions:

Quote:$this->upload->data()
This is a helper function that returns an array containing all of the data related to the file you uploaded.
Code:
Array
(
    [file_name]    => mypic.jpg
    [file_type]    => image/jpeg
  ...
    [is_image]     => 1
    [image_width]  => 800
    [image_height] => 600
    [image_type]   => jpeg
    [image_size_str] => width="800" height="200"
)



Resize only if bigger - El Forum - 10-07-2009

[eluser]Kamape[/eluser]
Yes, that's a great way to determine the width and height before eventual resizing.

Thanks!


Resize only if bigger - El Forum - 10-07-2009

[eluser]BrianDHall[/eluser]
[quote author="Kamape" date="1254940714"]Yes, that's a great way to determine the width and height before eventual resizing.

Thanks![/quote]

Its also a nice way to save a redundant call to getimagesize, because that's how the upload class gets the info Smile