Change image size according to proportion_PHP tutorial

WBOY
Release: 2016-07-13 10:38:51
Original
896 people have browsed it

/**
Change the image size according to the proportion (not generating thumbnails)
@param string $img image path
@param int $max_w Maximum zoom width
@param int $max_h Maximum zoom height
*/
function chImageSize ($img,$max_w,$max_h)
{
$size = @getimagesize($img);
          $w = $size[0];
         $h                                                                                                              //Calculate scaling ratio
@$w_ratio = $max_w / $w;
@$h_ratio = $max_h / $h;
//Determine the width and height of the processed image
If( ($w <= $max_w) && ($h <= $max_h) )
{
          $tn['w'] = $w;
          $tn['h'] = $h;
}  
else if(($w_ratio * $h) < $max_h)
{
          $tn['h'] = ceil($w_ratio * $h);
          $tn['w'] = $max_w;
}  
else
{
          $tn['w'] = ceil($h_ratio * $w);
          $tn['h'] = $max_h;
}  
$tn['rc_w'] = $w;
$tn['rc_h'] = $h;
Return $tn ;
}
?>

Function description and examples

Change image size proportionally (not generate thumbnails)

http://www.bkjia.com/PHPjc/735073.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735073.htmlTechArticle? /**Change the image size proportionally (not generate thumbnails) @param string $img image path @param int $max_w maximum zoom width @param int $max_h maximum zoom height*/ function chImageSize...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!