PHP Tutorial Scaling Small graph functions <?php Class My_lib_functions { # ******************************************** # object to Array # ******************************************** function Object2array ($obj) { foreach ($obj as $k => $v) { $arr [$k] = $v; Unset ($v); } return $arr; }
// ********************************************
//Get the picture width and height in the limited range
//$MX: The width of the image displayed on the page
//$my: The height of the image displayed on the page
//Here thumbnails are scaled to Y = $mx/$my;
// **********************************************
function Getpicxy ($picurl, $mx = 0, $my = 0) {
if (! $size = @GetImageSize ($picurl)) return false; GetImageSize is used to measure any image size and return the size of the image as well as the file type and a height/width text string for the <IMG> tag in the normal HTML file
if ($mx = = 0 && $my = = 0) return $size; Returns the size of the image when the value of the $MX and $my parameters is zero
if ($MX * $size [1]/$size [0] > $my) {//Judge when the $mx times the height of the image itself and the width of the image is greater than the width of the image displayed on the page
$newXY [0] = $my * $size [0]/$size [1]; Sets the value that produces a new image with a width of $mx multiplied by the width of the image itself and divided by the height of the image itself
$newXY [1] = $my; Sets the height of the resulting new image to the height of the page image display
}else{//Judge when $mx times the height of the image itself and the width of the image is not greater than the width of the image displayed on the page
$newXY [0] = $MX; Sets the width of the resulting new image to the width of the page image display
$newXY [1] = $mx * $size [1]/$size [0]; Sets the value that produces a new image with a width of $mx multiplied by the height of the image itself and divided by the width of the image itself
}
if ($size [0] <= $my and $size [1] <= $mx) {//Determine if the width of the image itself is less than equal to the width of the image displayed on the page and the image itself is less than equal to the height of the displayed image on the page
$newXY [0] = $size [0]; Sets the new width of the image to the width of the image itself
$newXY [1] = $size [1]; Set the image the height of the new Year production is the height of the image itself
}
return $newXY; Returns the new proportions of the image
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.