PHP Scale Small graph function

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags .mall array class function image php php class php tutorial

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 &lt;IMG&gt; tag in the normal HTML file


if ($mx = = 0 &amp;&amp; $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] &gt; $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] &lt;= $my and $size [1] &lt;= $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


}

Function getNewImageWH2 ($imageUrl, $maxWidth = 0, $maxHeight = 0, & $newWidth = 0, & $newHeight = 0) {
     if (! $imageSize = @GetImageSize ($IMAGEURL)) return false;
    if ($maxWidth = = 0 | | $maxHeight = = 0) {
        $newWidth   = $imageSize [0];
        $newHeight = $imageSize [1];
 } else {
        $newWidth   = $maxWidth;
         $newHeight = $newWidth * $imageSize [1]/$imageSize [0];
        if ($newHeight < $maxHeight) {
             $newHeight   = $maxHeight;
            $newWidth = $newHeight * $imageSize [0]/$ IMAGESIZE[1];
       }
&NBSP;&NBSP;&NBSP;&NBSP;&NBsp;   $imageSize [0] = $newWidth;
        $imageSize [1] = $newHeight;
   }
    return $imageSize;
}


}
?

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.