Function to zoom in or out an image proportionally

Source: Internet
Author: User
The function prototype is as follows: parameter description: $ oldwidth: Original image width $ oldheight: Original Image Height $ imgwidth: reduced or enlarged image width $ imgheight: reduced or enlarged image height returned: array: arraysize, where the index is: width and height, that is, arraysize [width], arraysize [height] functi

The function prototype is as follows:
Parameter description:
$ Oldwidth: Original image width
$ Oldheight: Original image height
$ Imgwidth: the image width that is reduced or enlarged.
$ Imgheight: The Image height that is reduced or enlarged.
Return value:
Array: arraysize, where the index is: width and height, I .e.: arraysize ['width'], arraysize ['height']
Function getimgsize ($ oldwidth, $ oldheight, $ imgwidth, $ imgheight)
{
// $ Width set by oldwidth, $ height set by oldheight, $ width of the imgwidth image, and $ height of the imgheight image;

// If a cell can be loaded into an image, it is displayed according to the actual size of the image;
If ($ imgwidth <= $ oldwidth & $ imgheight <= $ oldheight)
{
$ Arraysize = array ('width' => $ imgwidth, 'height' => $ imgheight );
Return $ arraysize;
}
Else
{
$ Suoxiaowidth = $ imgwidth-$ oldwidth;
$ Suoxiaoheight = $ imgheight-$ oldheight;
$ Suoxiaoheightper = $ suoxiaoheight/$ imgheight;
$ Suoxiaowidthper = $ suoxiaowidth/$ imgwidth;
If ($ suoxiaoheightper >=$ suoxiaowidthper)
{
// The cell height shall prevail;
$ Aftersuoxiaowidth = $ imgwidth * (1-$ suoxiaoheightper );
$ Arraysize = array ('width' => $ aftersuoxiaowidth, 'height' => $ oldheight );
Return $ arraysize;
}
Else
{
// The cell width prevails;
$ Aftersuoxiaoheight = $ imgheight * (1-$ suoxiaowidthper );
$ Arraysize = array ('width' => $ oldwidth, 'height' => $ aftersuoxiaoheight );
Return $ arraysize;
}
}
}

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.