/** * 获取等比高宽 * @param string $image_path 最大宽度 * @param int $max_width 最大宽度 * @param int $max_height 最大高度 */function getRatioSize($image_path, $max_width='', $max_height=''){ list($width, $height) = getimagesize($image_path); $max_width = abs($max_width)<=0 ? 1 : abs($max_width); $max_height = abs($max_height)<=0 ? 1 : abs($max_height); if(!($max_width>$width || $max_height>$height)){ $ratioh = $max_height/$height; $ratiow = $max_width/$width; $ratio = max($ratioh, $ratiow); // New dimensions $width = intval($ratio*$width); $height = intval($ratio*$height); } return array('width'=>$width, 'height'=>$height);}$image_path = "test2.jpg";$size = getRatioSize($image_path, 300, 100);echo '';