站长论坛

标题: 关于怎么样控制论坛里图片大小的问题中一个函数 [打印本页]

作者: tznktg    时间: 2007-9-27 22:29
标题: 关于怎么样控制论坛里图片大小的问题中一个函数
$url 要显示的图片地址
$conwidth 显示图片的最大宽度
$conheight 显示图片的最大高度
$link 图片的连接目标



[php]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;
}[/php]




欢迎光临 站长论坛 (http://www.tzlink.com/bbs/) Powered by Discuz! X3.2