Monday, August 18, 2014

GUIDE: Automatically resize phpBB avatars in post displays

  1. Open the includes/functions_display.php file in a text editor.
  2. 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;
    }
  3. Change the $inputwidth and $inputheight variables to suit your needs.
  4. 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) . '" />';

2 Comments:

At February 27, 2015 at 5:27 PM , Blogger Thiago Magri said...

Thanks a lot, RunasSudo!!! :D :D :D

 
At February 2, 2016 at 11:22 PM , Blogger Priya Sharma said...

Thanks for sharing such a informative article. I hope that this post is really useful for the people who looks for this.
Kartikeya Sharma

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home