challenger
(challenger)
中级会员
 
中级会员
UID 28330
精华
0
积分 387
帖子 387
金钱 387 喜悦币
威望 0
人脉 0
阅读权限 30
注册 2004-5-7
状态 离线
|
image.php
<?php
if (!$max_width)
$max_width = 100;
if (!$max_height)
$max_height = 80;
$image=$_GET[image];
//
$size = GetImageSize($image);
//
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
switch ($size[2]) {
case 1: //图片类型,1是GIF图
$src = @ImageCreateFromGIF($image);
break;
case 2: //图片类型,2是JPG图
$src = @imagecreatefromjpeg($image);
break;
case 3: //图片类型,3是PNG图
$src = @ImageCreateFromPNG($image);
break;
}
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header("Content-type: image/jpeg");
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
调用
a.html
<a href="<?=$url?>" target="_blank"><IMG SRC="image.php?image=<?=$url?>"></a>
$url为图片目录
|
|