Php generate small graph function proportionally-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? PhpclassMy_Lib_Functions {#************************************* * ****** # object to array #**************************** * *************** functionobject2array ($ obj) {& nbsp; for script ec (2); script

Class My_Lib_Functions {
#*************************************** *****
# Convert objects to Arrays
#*************************************** *****
Function object2array ($ obj ){
Foreach ($ obj as $ k => $ v ){
$ Arr [$ k] = $ v;
Unset ($ v );
}
Return $ arr;
}


//************************************** ******
// Obtain the image width and height within the specified range
// $ Mx: the width of the image displayed on the page
// $ My: the height of the image displayed on the page
// The principle of proportional scaling of the thumbnail here is x/y = $ mx/$ my;
//************************************** ********
Function getPicXY ($ picurl, $ mx = 0, $ my = 0 ){
If (! $ Size = @ GetImageSize ($ picurl) return false; // GetImageSize is used to determine the size of any image and return the image size, file type, and a height/width text string used for marking in a common HTML file
If ($ mx = 0 & $ my = 0) return $ size; // returns the image size when the values of $ mx and $ my are zero.
If ($ mx * $ size [1]/$ size [0]> $ my) {// determine when $ mx is multiplied by the Image Height and then divided by the image width greater than the image width displayed on the page
$ NewXY [0] = $ my * $ size [0]/$ size [1]; // set the width of the new image to $ mx multiplied by the image width and then divided by the image height.
$ NewXY [1] = $ my; // set the height of the new image to the height displayed on the page.
} Else {// determines when $ mx is multiplied by the height of the image and then divided by the image width, which is not greater than the image width displayed on the page.
$ NewXY [0] = $ mx; // you can specify the width of the new image to display.
$ NewXY [1] = $ mx * $ size [1]/$ size [0]; // set the width of the new image to $ mx multiplied by the height of the image and then divided by the width of the image.
}
If ($ size [0] <= $ my and $ size [1] <= $ mx) {// determine if the image width is less than or equal to the width of the displayed image on the page and the image height is less than or equal to the height of the displayed image on the page
$ NewXY [0] = $ size [0]; // set the new width of the image to the width of the image.
$ NewXY [1] = $ size [1]; // set the height of the New Year's image to the height of the image itself
}
Return $ newXY; // new proportion of the returned 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];
}
$ ImageSize [0] = $ newWidth;
$ ImageSize [1] = $ newHeight;
}
Return $ imageSize;
}


}
?>

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.