PHP之缩略图

<?php 

$imagefile="C:\Users\Administrator\Desktop\2.jpeg";
$imagattr=getimagesize($imagefile);  //图片大小
$maxx=$imagattr[0];  //宽
$maxy=$imagattr[1]; //高
$ext=$imagattr[2]; //图像类型
$mine=$imagattr['mime']; //图像格式
$big=imagecreatefromjpeg($imagefile);  //大

$x=200;
$y=100;

//等比列缩放
if(($x/$maxx)>($y/$maxy))
{
	$bili=$y/$maxy;
}else{
	$bili=$x/$maxx;
}
$x=floor($maxx*$bili);
$y=floor($maxy*$bili);
$small=imagecreatetruecolor($x, $y);
imagecopyresampled($small,$big,0,0,0,0,$x,$y,$maxx,$maxy);  //ss
switch($ext)
   {
   	 case 1:
   	 $imageout="imagegif";
   	 break;
   	 case 2:
   	 $imageout="imagejpeg";
   	 break;
   	 case 3:
   	 $imageout="imagepng";
   	 break;
   }
   header("content-type:{$mine}");

   //$imageout($small);
   $imageout($small);
imagedestroy($img);
imagedestroy($xiao);


?>

  

原文地址:https://www.cnblogs.com/mengluo/p/5545455.html