note 60462 added to function.abs
| From: | Josh at osu1 dot php dot net | Date: | Sun, 08 Jan 2006 00:06:44 +0000 |
| Subject: | note 60462 added to function.abs | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101374@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.abs.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60462
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60462&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60462&report=yes
Search -- http://master.php.net/manage/user-notes.php