I dug deep into the PHPBB code and added a little hack of my own, though I admit it still isn't perfect. Using php's getimagesize function I modify the image size tags as the BBCode is parsed (I'm only allowing BBCode, no HTML in my forums). Take a look:
Code: Select all
includes/bbcode.php
# Original image replacement code, commented so it does not execute
# $patterns[] = "#\[img:$uid\]([^?].*?)\[/img:$uid\]#i";
# $replacements[] = $bbcode_tpl['img'];
$pattern1 = "#\[img:$uid\]([^?].*?)\[/img:$uid\]#i";
preg_match_all($pattern1, $text, $imageURL);
foreach ($imageURL[1] as $key => $val){
if ($val){
$imageSize = getimagesize($val);
if ($imageSize[0] > 400){$imageWidth = 400; $imageHeight = $imageSize[1] * (400 / $imageSize[0]);}
else {$imageWidth = $imageSize[0]; $imageHeight = $imageSize[1];}
$pattern1 = "#\[img:$uid\]($val)\[/img:$uid\]#i";
$replacement1 = "<img src=\"$val\" height=\"$imageHeight\" width=\"$imageWidth\" border=\"0\" />";
$text = preg_replace($pattern1, $replacement1, $text);
}
}