Also, I should probably state what differentiates this MOD to the others currently in Beta stages. It tests the image on the server-side rather than on the client-side, do you don't get ugly temporary layout-breaks when the page loads.
IMPORTANT NOTES:
- This mod needs the "allow_url_fopen" directive turned on within your PHP installation. To test for this directive, go to the "PHP Information" page within the phpBB3 ACP. The directive is listed under the "PHP Core" section.
- There could be adverse load-time effects when using this MOD, due to the getimagesize() PHP function downloading the entire image when it is called. I have yet to find a solution to this, however.
MOD Name: Auto Image Resize
MOD Version: 0.0.2
Author: MaidenFan
MOD Description: Automatically resizes images that are bigger than a given size, and links to the full-size image in a new window using JS (due to the XHTML target attribute being deprecated).
phpBB Version: 3.0.0
Language: Language-independant
License: GNU General Public License v2
Files Edited: 1
Files Uploaded: 0
Mod Installation
Open: includes/bbcode.php
Find line:
Code: Select all
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id),
Code: Select all
'#\[img:$uid\](.*?)\[/img:$uid\]#ise' => "\$this->bbcode_second_pass_img('\$1')",
Code: Select all
}
?>
Code: Select all
//------------- START IMAGE RESIZE MOD ----------------
/**
* Second parse img tag
*/
function bbcode_second_pass_img($url) {
global $user;
$dimensions = @getimagesize($url);
$resize = false;
$return = "";
// Resize testing
if ($dimensions[0] > 500) {
$resize = true;
$ratio = 500/$dimensions[0];
$imageHeight = round($dimensions[1]*$ratio);
$imageWidth = "500";
$window_width = $imageWidth+10;
$window_height = $imageHeight+10;
} else {
$imageWidth = $dimensions[0];
$imageHeight = $dimensions[1];
}
// Construct the HTML, placing the JS link if the image has been resized
if ($resize){ $return .= "<a href=\"javascript::\" onclick=\"window.open('$url','_blank','Image', 'width=$window_width, height=$window_height, scrollbars=yes, location=no, directories=no, menubar=no, status=no, toolbar=no, top=10, left=10')\">"; }
$return .= "<img src=\"$url\" alt=\"" . $user->lang['IMAGE'] . "\"";
if ($resize){ $return .= " width=\"$imageWidth\" height=\"$imageHeight\""; }
$return .= " />";
if ($resize){ $return .= "</a>"; }
return $return;
}
//------------- END IMAGE RESIZE MOD ----------------
Planned Changes
- Converting MOD format to MODX
- Fully integrating the MOD into the phpBB template system (at the moment the MOD manually overrides templates BBCode)
- Integration into the phpBB3 ACP
0.0.3 - Edited JavaScript to allow scrollbars where needed on popup windows
0.0.2 - Edited the "find" condition for the BBCode regular expression.
0.0.1 - First release