分享

PHP 调整图像尺寸

 马超读书的季节 2015-12-25
/********************** *@filename - path to the image *@tmpname - temporary path to thumbnail *@xmax - max width *@ymax - max height */ 
function resize_image($filename$tmpname$xmax$ymax) { 
    $ext explode("."$filename); 
    $ext $ext[count($ext)-1]; 
    if($ext == "jpg" || $ext == "jpeg"$im = imagecreatefromjpeg($tmpname); 
    elseif($ext == "png"$im = imagecreatefrompng($tmpname); 
    elseif($ext == "gif"$im = imagecreatefromgif($tmpname); 
     
    $x = imagesx($im); 
    $y = imagesy($im); 
    if($x <= $xmax && $y <= $ymaxreturn $im
    if($x >= $y) { 
        $newx $xmax
        $newy $newx $y $x
    }  else 
        $newy $ymax$newx $x $y $newy
    }
    $im2 = imagecreatetruecolor($newx$newy); 
    imagecopyresized($im2$im, 0, 0, 0, 0, 
    floor($newx), floor($newy), $x$y); 
    return $im2;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多