Heim  >  Artikel  >  Backend-Entwicklung  >  按照比例改变图片大小_PHP教程

按照比例改变图片大小_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:38:51903Durchsuche


/** 
    按照比例改变图片大小(非生成缩略图) 
    @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 ; 
}
?>


函数描述及例子

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735073.htmlTechArticle? /** 按照比例改变图片大小(非生成缩略图) @param string $img 图片路径 @param int $max_w 最大缩放宽 @param int $max_h 最大缩放高 */ function chImageSize...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn