CodeIgniter Forums
how to check width and height of image before resize - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to check width and height of image before resize (/showthread.php?tid=54766)



how to check width and height of image before resize - El Forum - 09-24-2012

[eluser]Tống Kiện Phi[/eluser]
In the example Image Manipulation Class i saw this code:

Code:
$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']  = 75;
$config['height'] = 50;

$this->load->library('image_lib', $config);

$this->image_lib->resize();

Now, i want to check size image if width more than 150px it's must resize, on the contrary not resize


how to check width and height of image before resize - El Forum - 09-24-2012

[eluser]NotDior[/eluser]
http://php.net/getimagesize - Would be your best bet.


how to check width and height of image before resize - El Forum - 09-24-2012

[eluser]memVN[/eluser]
Ok
When you was uploaded success - function upload will return an array as $upload = $this->upload->data();

In array $upload you has key $upload['width'];

So in order to check width before resize you can do like

if($upload['width'] > 150)
{
//Do resize
}