RE: [PHP] checking the aspect ratio of an images

From: Date: Wed, 06 Jun 2007 11:09:29 +0000
Subject: RE: [PHP] checking the aspect ratio of an images
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-256163@lists.php.net to get a copy of this message
> -----Original Message----- > From: blueboy [mailto:ross@aztechost.com] > Sent: 06 June 2007 11:41 > To: php-general@lists.php.net > Subject: [PHP] 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

« previous php.general (#256163) next »