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