|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
参加PHP开发学习,或许只是一次偶然的想法吧!只是想在走向社会之前体验、学习在一个公司或者说是项目团队之中如何去更有效的沟通、交流、共同合作,还有就是为毕业实习找工作增加伐码。缩略图|显示 <?php
function CreateThumbnail($path,$newFileName,$width=100,$height=100)
{
@$s_img = getimagesize($path);
@$type = $s_img[2];
switch($type)
{
case 1 : @$im = imagecreatefromgif($path);break;
case 2 : @$im = imagecreatefromjpeg($path); break;
case 3 : @$im = imagecreatefrompng($path);break;
default: $im = false;
break;
}
@$s_width = imagesx($im);
@$s_height = imagesy($im);
$sizexy = getScaleImage($path,$width,$height);
$width = $sizexy[0];
$height = $sizexy[1];
if($im)
{
$im2 = imagecreatetruecolor($width,$height);
imagecopyresized ($im2,$im,0,0,0,0,$width,$height,$s_width,$s_height);
imagejpeg($im2,$newFileName);
}
return false;
}
function getScaleImage($image,$perfectWidth,$perfectHeight)
{
if (realpath($image) != false)
{
$sizeArray = getimagesize($image);
$sizeX = $sizeArray[ 0 ] ;
$sizeY = $sizeArray[ 1 ] ;
if ($perfectWidth!=0 && $perfectHeight==0)
{
if ($sizeX>$perfectWidth)
{
$scale = $sizeX/$sizeY ;
$sizeX = $perfectWidth;
$sizeY = floor($sizeX/$scale);
}
}
if ($perfectHeight != 0 && $perfectWidth == 0)
{
if ($sizeY > $perfectHeight)
{
$scale = $sizeY / $sizeX ;
$sizeY = $perfectHeight;
$sizeX = floor($sizeY / $scale);
}
}
if ($perfectHeight != 0 && $perfectWidth != 0)
{
$sizeX = $perfectWidth;
$sizeY = $perfectHeight;
}
$tmp[] = $sizeX;
$tmp[] = $sizeY;
}
else
{
$tmp[] = 0;
}
return $tmp;
}
$tm = getScaleImage("http://www.pushad.com/Info/100_3353.jpg",0,0);
echo "<img src="http://www.pushad.com/Info/100_3353.jpg" width='".$tm[0]."' height='".$tm[1]."' />";
foreach ($tm as $v)
{
echo $v."<br>";
}
//CreateThumbnail("http://www.pushad.com/Info/100_3353.jpg","aa.gif",100,0);
?>
因为函数实在是太多了,慢慢的你就会知道,知道有这个函数就可以。 |
|