[2.0.18] Simple Mod Resize Images

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in here. No new MODs will be accepted into the MOD Database for phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.


Very Good
No votes
Total votes: 20

Registered User
Posts: 4
Joined: Tue Mar 28, 2006 2:46 pm
Location: Durham, NC

Alternate mod

Post by trek7k »

I tried a similar javascript mod to the one mentioned above but I wasn't satisfied. The images resize correctly but my page layout was still broken since the images are resized AFTER the html is loaded leaving me with white space where the large images USED to be.

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


# 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);
This code resizes images such that none are wider than 400 pixels (just replace 400 with your desired width in the code above). The problem I'm finding now is that some of my users store their photos on servers that don't allow URL requests of files (and so the getimagesize function fails for those images). Anyone have any ideas?
Eddy Kiprich
Registered User
Posts: 149
Joined: Sun Dec 18, 2005 1:22 pm
Location: The Netherlands

Post by Eddy Kiprich »

Can it be possible to auto-resize images on the blogging system as well?
Registered User
Posts: 4
Joined: Wed Jun 21, 2006 2:34 am

Post by Spydey »

Eddy Kiprich wrote:
MennoniteHobbit wrote:Since the MOD uses JavaScript, you should check to see if your browser supports JavaScript ("supports" also including "is enabled").

Since the code is put into overall_header.tpl, you should note that the resize images feature will apply to all images. The not loading bit seems to be different, however. It may just be your Internet connection.

My laptop supports javascript and it is enabled. Also I think that every user on our forum suffers missing pictures. Only with a refresh (F5) the pictures will return.

Hi guys, I am also seeing the same issue as everyone else. This only occurs in IE btw. I usually have to press F5 twice before the pictures reappear. Any ideas on how to fix it?
Registered User
Posts: 29
Joined: Sat Aug 19, 2006 4:04 am

any update?

Post by surfermorph »

Hi there

I'm having the same problem using this mod with IE - essentially having to refresh the page a couple times for the images to appear. Is there any fix or suggestions?

Alternatively, is there any possibility of "un-installing" this mod?

Thanks in advance for your help.
Registered User
Posts: 12
Joined: Mon Sep 27, 2004 3:04 am

Post by jamiejones »

try this one:


Simple to install, and demo on that page too.
Registered User
Posts: 1
Joined: Thu Nov 23, 2006 4:25 pm

Post by James_jamz »

I keep getting the error "Stack Overflow at line:"

Any ideas?
Registered User
Posts: 21
Joined: Thu Sep 28, 2006 10:22 pm

Post by rocketsep »

Femma wrote:
jessan wrote:Didnt work. Nothing happens

Same here, did not work.

it did not work the first time I tried it. There seems to be an issue as to the location of the js file.
copy SMRcode.js to templates/SMRcode.js

It worked after I moved SMRcode to templates/subsilver/SMRcode.js (substitute subsilver for the style you are using)
nycore wrote: Does this resize based on some preset width or is it adjustable by admin? I dont see any admin files edited. No admin adjustability?

You need to edit the 4th line in SMRcode.js
SMR_confMaxDim = 350; // pixels

Change the '350' to the maximum size in pixels you require
Registered User
Posts: 185
Joined: Fri Feb 24, 2006 6:14 pm
Location: Slovenia

Post by Veron »

I would like to ask if it is possible to make some changes to this code, so pictures smaller then 430 would not get link.

I mean that "function SMR_setLink(obj)" would not be set to pictures smaller then 430.
Probably will be needed one IF (this.width=<430).. else System.out(0)
. But i can not figure out how to do it proparly to work normally.

I end, picuters bigger then 430 must get liked (function SMR_setLink(obj)) and pictures smaller or 430 must not get link (function SMR_setLink(obj) must not be included)

Code: Select all

//** SMR_RESIZE_MOD: CONFIGURATION **********************************
SMR_confMaxDim = 430; // pixels

//** SMR_RESIZE_MOD: START CODE *************************************

function SMR_resize(obj) {

   thisWidth = obj.width;
   thisHeight = obj.height;
   if(thisWidth > thisHeight) thisMaxDim = thisWidth;
   else thisMaxDim = thisHeight;
   if(thisMaxDim > SMR_confMaxDim) {
      thisMinDim = Math.round((((thisWidth > thisHeight)?thisHeight:thisWidth) * SMR_confMaxDim) / thisMaxDim); 
      if(thisWidth > thisHeight) {
         thisWidth = SMR_confMaxDim;
         thisHeight = thisMinDim;
      } else {
         thisHeight = SMR_confMaxDim;
         thisWidth = thisMinDim;
   } // if(thisMaxDim > SMR_confMaxDim)

   obj.height = thisHeight;
   obj.width = thisWidth;

function SMR_setLink(obj) {
   thisInnerHtml = obj.innerHTML;
   tmpArray = thisInnerHtml.split(' src=\"');
   tmpArray = tmpArray[1].split('"');
   obj.href = tmpArray[0];
//** SMR_RESIZE_MOD: END ********************************************
User avatar
Registered User
Posts: 404
Joined: Sun Mar 31, 2002 1:40 pm
Location: Estes Park, USA

Post by freddie »

this mod isn't working on all images on my board ...
Registered User
Posts: 447
Joined: Mon Dec 11, 2006 3:41 pm
Location: Bulgaria, Sofia

Post by diabolic.bg »

Not bad but again it have a problem with IE - some pictures hide. 8O
Registered User
Posts: 251
Joined: Thu Mar 23, 2006 6:46 pm

Post by loyal_and_true »

Works great with big images thanks...

only thing is on my forum when Thumbnail Images are posted they display perfectly fine but when you click the thumb its meant to go the large image right well it goes to the same small thumbnail as displayed in the thread with the size below it...

Its just started doing it never done it before

Any Ideas ??

User avatar
Support Team Member
Support Team Member
Posts: 52236
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Post by Brf »

Is that a link to an imageshack thumb?
Registered User
Posts: 251
Joined: Thu Mar 23, 2006 6:46 pm

Post by loyal_and_true »

Brf wrote: Is that a link to an imageshack thumb?

User avatar
Support Team Member
Support Team Member
Posts: 52236
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Post by Brf »

Ah. Then you made a thumb of the thumb. You should be inserting the link to the actual picture, not the thumb.
Registered User
Posts: 251
Joined: Thu Mar 23, 2006 6:46 pm

Post by loyal_and_true »

I am posting the correct line!

Thumbnail for forums (1)

Code: Select all


It works on here but on my forum It goes to a page of the thumb itself
Post Reply

Return to “[2.0.x] MOD Database Releases”