Home > Backend Development > PHP Tutorial > PHP缩放图片函数

PHP缩放图片函数

WBOY
Release: 2016-06-20 13:02:16
Original
931 people have browsed it

function resize_image($filename, $tmpname, $xmax, $ymax)  <br />{  <br />    $ext = explode(".", $filename);  <br />    $ext = $ext[count($ext)-1];  <br />   <br />    if($ext == "jpg" || $ext == "jpeg")  <br />        $im = imagecreatefromjpeg($tmpname);  <br />    elseif($ext == "png")  <br />        $im = imagecreatefrompng($tmpname);  <br />    elseif($ext == "gif")  <br />        $im = imagecreatefromgif($tmpname);  <br />       <br />    $x = imagesx($im);  <br />    $y = imagesy($im);  <br />       <br />    if($x <= $xmax && $y <= $ymax)  <br />        return $im;  <br />   <br />    if($x >= $y) {  <br />        $newx = $xmax;  <br />        $newy = $newx * $y / $x;  <br />    }  <br />    else {  <br />        $newy = $ymax;  <br />        $newx = $x / $y * $newy;  <br />    }  <br />       <br />    $im2 = imagecreatetruecolor($newx, $newy);  <br />    imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);  <br />    return $im2;   <br />}
Copy after login


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