> -----Original Message----- > From: blueboy [mailto:ross@xxxxxxxxxxxxx] > Sent: 06 June 2007 11:41 > To: php-general@xxxxxxxxxxxxx > Subject: checking the aspect ratio of an images > > > 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. > > This is my code so far. > > $max_height = "500"; // This is in pixels > $max_width = "500"; // This is in pixels > > list($width, $height, $type, $w) = > getimagesize($_FILES['userfile']['tmp_name']); > > if($width > $max_width || $height > $max_height) > { > > } > This is basic maths. 4:3 means and aspect ratio of 1:0.75 or the height is 0.75 times the width. Therefore, just check that: if ($height/$width != 0.75) // Image not 4:3 landscape You seem to imply this is an approx restriction, so just increase your acceptable range of values, e.g. $ratio = $height/$width; if ($ratio < 0.7 || $ratio > 0.8) // Ratio not acceptable. Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php