• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

How to validate the image dimension of certain range?

I have a preset image variable $maxwidth and $maxheight of 110 and 176 pixels.

I managed to obtain the image dimension in the variable of $width and $height.

176 / 110 is equal to 1.6

I would like to validate an image using a variable $acceptable so that $height / $width is within the range of 1.58 ~ 1.62.

$acceptable will be equal to 1 if the image aspect ratio is within 1.58 ~ 1.62, or else 0 will be assigned.

I need this short piece of coding for validation.
2 Solutions
$acceptable = 0;
if($height / $width >= 1.58 && $height / $width <= 1.62)$acceptable=1;
$acceptable = 0+($width*1.58<=$height && $height <= $width*1.62);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now