Re: checking the aspect ratio of an images

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Wednesday, June 6, 2007, 11:41:19 AM, you wrote:

> I want to force users to insert landscape rather portrait images. I don't
> want to be too pedantic about it but they do need to have an approximate 4x3
> aspect ratio.

You can't really be 'approximate' when coding. You need to set some
hard values to check against. So work out what your extremes will be
first.

A 4x3 image has an aspect ratio of 1.33

So decide what your max and min ratios will be and then check the
aspect ratio of the image they upload.

If they upload a 320x200 it'll have a ratio of 1.60
If they upload a 200x320 it'll have a ratio of 0.63
If they uploaded a 200x200 the ratio is exactly 1

So if you want the image to be landscape, it'll always have a ratio of
above 1.0. If you don't want it stupidly landscape (i.e. 1600x300)
then just set your maximum ratio to something like 1.6.

Once you've set your boundaries your 'if' statement becomes a whole
lot easier to write.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux