Monday, August 18, 2014

GUIDE: Automatically resize phpBB avatars in post displays

$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;
}