您的位置:首页 > 编程语言 > PHP开发

PHP之缩略图

2016-05-31 12:21 519 查看
<?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);

?>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: