tznktg 发表于 2007-9-27 22:29:45

关于怎么样控制论坛里图片大小的问题中一个函数

$url 要显示的图片地址
$conwidth 显示图片的最大宽度
$conheight 显示图片的最大高度
$link 图片的连接目标



function showpic($url,$conwidth,$conheight,$link)
{

$picSize = @GetImageSize($url);
preg_match("!width=\"(.*)\" height=\"(.*)\"!", $picSize['3'], $tempSize);

$realwidth = $tempSize['1'];
$realheight = $tempSize['2'];

$tWidth = $realwidth / $conwidth;
$tHeight = $realheight / $conheight;

if ($realwidth > $conwidth OR $realheight > $conheight)
{
if ($tWidth > $tHeight)
{
$width = $conwidth;
$height = number_format($realheight / $tWidth);
}
elseif ($tWidth < $tHeight)
{
$height = $conheight;
$width = number_format($realwidth / $tHeight);
}
else
{
$width = $conwidth;
$height = $conheight;
}
}
else
{
$width = $realwidth;
$height = $realheight;
}
if(!empty($link))
{
$pic_url="";
}
else
{
$pic_url="";
}
return $pic_url;
}
页: [1]
查看完整版本: 关于怎么样控制论坛里图片大小的问题中一个函数

网站推广