PHP完成照片放缩作用并适用多种多样文件格式

2021-04-08 20:01

function getSizeImage($filename,$new_width,$new_height){ list($width, $height)=getimagesize($filename); $n_w=$width/$new_width; $n_h=$height/$new_height; $n_w = $width/$n_w; $n_h = $height/$n_h; $new=imagecreatetruecolor($n_w, $n_h);+ $ext = (@end(explode(".",$filename))); switch ($ext) { case 'png':  $img = imagecreatefrompng($filename); break; case 'gif': $img = imagecreatefromgif($filename); break; case 'jpeg': $img = imagecreatefromjpeg($filename); break; case 'jpg':  $img = imagecreatefromjpeg($filename); break; default: dd('不兼容该种类'); break; } //copy一部分图象并调节 imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height); //图象輸出新照片、另存为 imagejpeg($new,$filename); imagedestroy($new); imagedestroy($img); }


扫描二维码分享到微信

在线咨询
联系电话

020-66889888