note 60462 deleted from function.abs by googleguy
| From: | googleguy@php.net | Date: | Sat, 19 Jan 2013 03:43:16 +0000 |
| Subject: | note 60462 deleted from function.abs by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193229@lists.php.net to get a copy of this message | ||
Note Submitter: Josh
----
Let's say you are resizing images to a standard size that can be expressed as a ratio
(width/height). The problem I came into was that I wanted to be reasonable with the proportion of
the images that my customer is uploading (couldn't we all use a little less horizontal on
pictures?), but I wanted to reject the horizontal pictures when they were uploading vertical ones.
So I wanted to accept proportions of images that were within a reasonable threshold (+ or -) of what
I will be resizing them to.
Assuming a standard of 1 to 4 (0.25) and a threshold of no more than 0.05 deviation, then the number
0.30 and 0.20 would return true and 0.19 would return false.
<?php
function threshold($given,$thresh,$standard)
{
return (abs($given-$standard)<=$thresh) ? true : false;
}
?>