Seite 1 von 1

Bild zu grosß - ohne mod Bildgröße ändern?!

Verfasst: 12.12.2010 08:12
von croxxx69
hallo,

also leider hatte ich im admin bereich die maximale größe der geposteten bilder nicht eingestellt. jetzt habe ich es auf max 780x780 eingestellt (hoffe das reicht, damit die bilder nicht, im wahrsten sinnde des wortes, den rahmen sprengen).

aber dies löst ja nur das problem der bilder die in der zukunft upgeloadet werden, doch die vorher im forum sind, bleiben ja so wie sie sind. weil bei einem user und in einem thema die bilder aus dem rahmen rausspringen, wollte ich euch fragen wie ich diese paar bilder, ohne jetzt komplitzierte mods zu installieren, verkleinern kann?

Re: Bild zu grosß - ohne mod Bildgröße ändern?!

Verfasst: 12.12.2010 09:37
von Lucan
Hallo,

das ist wohl nicht möglich, aber das Snippet hier (weiss gerade nich mehr wo ich es her hab) funktioniert bestens.

After being pestered by members for an image-resize Mod on a forum I recently converted to phpBB3 from phpBB2, I thought I'd hard-code one seeing as there's none that I can easily find here. OK, so it's not the most elegant solution in the world and relies on hard-coding the resize limits, but at least it works ;).

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:

1. 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.
2. 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 Overview

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),


Replace with:

Code: Select all
'#\[img:$uid\](.*?)\[/img:$uid\]#ise' => "\$this->bbcode_second_pass_img('\$1')",



Find: (essentially the last close-curly-brace and the PHP end-tag)

Code: Select all
}

?>



Before, add:

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 ----------------



End of 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


Change Log
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