GUIDE: Automatically resize phpBB avatars in post displays
- Open the includes/functions_display.php file in a text editor.
- Above the return '<img src="' . (str_replace( … line, insert the code:
$inputwidth = 100; $inputheight = 100; // So then if the image is wider rather than taller, set the width and figure out the height if (($avatar_width/$avatar_height) > ($inputwidth/$inputheight)) { $outputwidth = $inputwidth; $outputheight = ($inputwidth * $avatar_height)/ $avatar_width; } // And if the image is taller rather than wider, then set the height and figure out the width elseif (($avatar_width/$avatar_height) < ($inputwidth/$inputheight)) { $outputwidth = ($inputheight * $avatar_width)/ $avatar_height; $outputheight = $inputheight; } // And because it is entirely possible that the image could be the exact same size/aspect ratio of the desired area, so we have that covered as well elseif (($avatar_width/$avatar_height) == ($inputwidth/$inputheight)) { $outputwidth = $inputwidth; $outputheight = $inputheight; }
- Change the $inputwidth and $inputheight variables to suit your needs.
- Replace the return '<img src="' . (str_replace( … line with:
return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $outputwidth . '" height="' . $outputheight . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';