Home > php教程 > php手册 > 按照比例改变图片大小

按照比例改变图片大小

WBOY
Release: 2016-06-13 09:43:14
Original
1048 people have browsed it


/** 
    按照比例改变图片大小(非生成缩略图) 
    @param string $img 图片路径 
    @param int $max_w 最大缩放宽 
    @param int $max_h 最大缩放高 
*/ 
function chImageSize ($img,$max_w,$max_h) 

    $size = @getimagesize($img); 
        $w = $size[0]; 
        $h     =    $size[1]; 
    //计算缩放比例 
    @$w_ratio = $max_w / $w; 
    @$h_ratio =    $max_h / $h; 
    //决定处理后的图片宽和高 
    if( ($w     { 
        $tn['w'] = $w; 
        $tn['h'] = $h; 
    } 
    else if(($w_ratio * $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 ; 
}
?>


函数描述及例子

按照比例改变图片大小(非生成缩略图)

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template