Ok here is my little avatar max size hack.
It works fine on my site but no promisies that it will work elsewhere.
Sorry about the messy code, (Im sure there is a neater more efficent way of doing this but, hey, it works) but im a php n00b, this is my first hack
Anyone can use this in their hack if they wish, just keep the commented credit intact.
Anyhow, this is the code.
PHP Code:
// display avatar - resize if too big
// By Bill - [url]http://www.billspaintball.com[/url]
$file = "http://www.yourdomain.com/pathto/forums/$bbuserinfo[avatarurl]"; // Path to pic
$maxw = 130; // Max thumbnail width
$maxh = 140; // Max thumbnail height
list($width, $height, $type) = getimagesize($file);
if ( $width <= $maxw AND $height <= $maxh )// check width and height
{// if width and height under size display unchanged
echo "<img src=\"$file.$type\" align=\"center\" border=\"0\">";
}
else
{
if ($width > $maxw)//check if width is too wide
{ // if it is, resize
$ratio = $width / $maxw; //work out resize ratio
$newwidth = $maxw; // new width
$newheight = ($height / $ratio); // new height at this resize
}
else
{
$newheight = $height; // if width is ok, set this cos we need it later
$newwidth = $width; // if width was ok, set this cos we ned it later
}
If ($newheight <= $maxh )
{
// if current height is ok, were done.
}
else // either origional or resized height is too big
if( $newheight >= $maxh )
{ // if resized height is still too big we resize it
$ratio2 = $newheight / $maxh; //work out resize ratio
$newheight = $maxh; // give $newheight a new value
$newwidth = ($newwidth / $ratio2); // new width at this resize
} // the value of $newwidth has just been changed
else
{// if were here then origional height is too big so we resize it
$ratio2 = $newheight / $maxh; //work out resize ratio
$newheight = $maxh; // give $newheight a new value
$newwidth = ($newwidth / $ratio2); // new width at this resize
}
// now we can finally display resized pic
echo "<img src=\"$file.$type\" border=\"0\" width = \"$newwidth\" height = \"$newheight\" align=\"center\">"; // display resized pic
}
Instructions.
Find this section in the origional code.
Its about half way through the step 2 section.
PHP Code:
</td></tr><tr><td width=10%><a href=\"http://www.yourdomain.com/forums/profile.php?$session[sessionurl]&do=editavatar\"><img src=\"$bbuserinfo[avatarurl]\" border=\"0\"></a></td><td width=50%>
Change it to
PHP Code:
</td></tr><tr><td width=10%><a href=\"http://www.yourdomain.com/forums/profile.php?$session[sessionurl]&do=editavatar\">";
//insert my new code here!!!
echo "</a></td><td width=50%>
You need to edit 2 lines in my code
$maxw is the maximum width of the avatar. Anything bigger will be resized to this.
$maxh is the maximum height of the avatar. Anything bigger will be resized to this.
Anything smaller will not be resized up since that can make them look ugly and pixelated.
All resized pics will retain their origional width/height proportions.
The pic will be resized so that both width and height will fix in the max sizes you have choosen.