note 116846 added to function.sqrt
| From: | justin at hoogs dot com dot au | Date: | Tue, 10 Mar 2015 04:12:35 +0000 |
| Subject: | note 116846 added to function.sqrt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201904@lists.php.net to get a copy of this message | ||
As we all know, the square of the hypotenuse is equal to the sum of the squares of the other two
sides of a right triangle (a2 + b2 = c2).
With that in mind I created a quick way to reduce images to a maximum area without messing up
width/height constraints.
<?php
list($width_orig, $height_orig) = getimagesize($img);
$max_a = 500000; // maximum area in pixels
$width = $width_orig;
$height = $height_orig;
$area = $width * $height;
if ($area > $max_a) {
$mult = sqrt($max_a) / sqrt($height * $width);
$width *= $mult;
$height *= $mult;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 110.148.168.237
----
Manual Page -- http://php.net/manual/en/function.sqrt.php
Edit -- https://master.php.net/note/edit/116846
Del: integrated -- https://master.php.net/note/delete/116846/integrated
Del: useless -- https://master.php.net/note/delete/116846/useless
Del: bad code -- https://master.php.net/note/delete/116846/bad+code
Del: spam -- https://master.php.net/note/delete/116846/spam
Del: non-english -- https://master.php.net/note/delete/116846/non-english
Del: in docs -- https://master.php.net/note/delete/116846/in+docs
Del: other reasons-- https://master.php.net/note/delete/116846
Reject -- https://master.php.net/note/reject/116846
Search -- https://master.php.net/manage/user-notes.php