How to validate the image dimension of certain range?

Posted on 2011-04-28
Last Modified: 2013-12-25
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.
Question by:jay28lee
    LVL 12

    Accepted Solution

    $acceptable = 0;
    if($height / $width >= 1.58 && $height / $width <= 1.62)$acceptable=1;
    LVL 84

    Assisted Solution

    $acceptable = 0+($width*1.58<=$height && $height <= $width*1.62);

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now