CodeIgniter Forums

Full Version: Get orientation (landscape/ portrait) of image
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum


Maybe I'm overlooking something in the CI docs (and PHP docs), but is there an easy way to get the orientation of an image?

Basically I want to know whether an uploaded imagefile is portrait or landscape, and then resize it accordingly.

Any ideas?


El Forum

[eluser]Johan André[/eluser]
If you use CI Upload-library use $this->upload->data() (which returns an array) and check it for key "image_width" and "image_height".

If width > height then image is landscape, if width < height then image is portrait.
If width = height then image is square! Smile

El Forum

Yeap .. The upload library does the trick. I was searching for image_width and image_height in the image library. This works great.


El Forum

I forgot upload class had it. I knew it was somewhere. I was going to suggest the php getimagesize function.