[ABD] Auto Image Resize 0.0.3 (Non-JavaScript)

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

[ABD] Auto Image Resize 0.0.3 (Non-JavaScript)

Post by MaidenFan »

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
Last edited by DavidIQ on Thu Aug 05, 2010 12:46 pm, edited 18 times in total.
Reason: Marked as abandoned. Please contact a member of the MOD Team to reclaim topic
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
moustafamin
Registered User
Posts: 230
Joined: Thu Aug 30, 2007 8:10 am

Re: [BETA] Auto Image Resize

Post by moustafamin »

does it work with hoteditor?
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

Re: [BETA] Auto Image Resize

Post by MaidenFan »

moustafamin wrote:does it work with hoteditor?
I haven't tested it, as Hoteditor is a third-party addon to phpBB that I don't use. If this "Hoteditor" uses the phpBB BBCode engine to parse images, then I assume so, but as I said it's untested - so you're welcome to try it but there's no guarantees either way :).
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Spaniel
Registered User
Posts: 159
Joined: Sun Dec 30, 2007 3:51 am

Re: [BETA] Auto Image Resize - Non-JavaScript

Post by Spaniel »

Thanks so much for this - image resizing is such an essential feature :)
moustafamin
Registered User
Posts: 230
Joined: Thu Aug 30, 2007 8:10 am

Re: [BETA] Auto Image Resize

Post by moustafamin »

MaidenFan wrote: If this "Hoteditor" uses the phpBB BBCode engine to parse images, then I assume so,
Well I'm not so expert to tell you so :) ..
but there is an issue causing all the Image resize scripts to not work with hoteditor..
hope yours will :(
User avatar
Novakov
Registered User
Posts: 9
Joined: Wed Oct 18, 2006 1:28 pm

Re: [BETA] Auto Image Resize - Non-JavaScript

Post by Novakov »

I found two matches

Code: Select all

'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> $this->bbcode_tpl('img', $bbcode_id),
and..

Code: Select all

'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),

who from these two I must replace?
TaleTN
Registered User
Posts: 121
Joined: Tue Mar 18, 2008 4:24 pm
Location: The Netherlands

Re: [BETA] Auto Image Resize - Non-JavaScript

Post by TaleTN »

This is an interesting approach to image resizing :) ... But won't this terribly slow down things? After all, every image has to be downloaded twice, once by the server and then by the client, right?

- Tale
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

Re: [BETA] Auto Image Resize - Non-JavaScript

Post by MaidenFan »

Novakov wrote:who from these two I must replace?
My apologies, replace only the first match. I'll update the MOD instructions to search for the full line :)
TaleTN wrote:This is an interesting approach to image resizing :) ... But won't this terribly slow down things? After all, every image has to be downloaded twice, once by the server and then by the client, right?
I'm not sure if it'll slow things down - I've had the MOD in place on my own forum for some time and I haven't noticed any speed issues. The "getimagesize()" function of PHP just analyses the image at the given URL - as far as I'm aware it doesn't actually download the entire image.

Has anyone else got this working?
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
TaleTN
Registered User
Posts: 121
Joined: Tue Mar 18, 2008 4:24 pm
Location: The Netherlands

Re: [BETA] Auto Image Resize - Non-JavaScript

Post by TaleTN »

MaidenFan wrote:I'm not sure if it'll slow things down - I've had the MOD in place on my own forum for some time and I haven't noticed any speed issues. The "getimagesize()" function of PHP just analyses the image at the given URL - as far as I'm aware it doesn't actually download the entire image.
I've had previous speed issues with the image size limiting options of phpBB3 (posting 30+ images from 10+ different hosts took up to 3 minutes). I've just checked, they also use getimagesize(). When I had these issues I did some testing, and I got the impression that getimagesize() actually downloaded the entire image every time I edited the post.

- Tale
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

Re: [BETA] Auto Image Resize - Non-JavaScript 0.0.2

Post by MaidenFan »

This is actually true, I've just tested it on the forum I run the code on both with and without the call to getimagesize() and it was definitely faster without.

I'm not sure what I could do to speed up the call, one idea may be to flush the buffer to the page every time a post is loaded, so that the user doesn't have a massive wait for the whole page to load, but the load is incremental. Not entirely sure how to implement it though, I've tried placing flush() and ob_flush(); calls at several points in the code, but nothing seems to work.

Edit

Another, altogether more drastic approach would be to implement a database table of image URLs and their respective widths and heights, as database queries are undoubtedly quicker than getimagesize() calls. Every time the script was passed a URL, it would check it against the database, and then only if it wasn't present in the database would getimagesize() be called. Once the height and width was retrieved, it would be stored in the database. The downside of this is that it doesn't take into account instances when the image dimensions change, for example on Last.FM signatures.

Any help and opinions would be appreciated :)
Last edited by MaidenFan on Wed Apr 09, 2008 10:52 am, edited 1 time in total.
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Bawls
Registered User
Posts: 7
Joined: Wed Apr 09, 2008 3:28 am

Re: [BETA] Auto Image Resize 0.0.2 (Non-JavaScript)

Post by Bawls »

Fatal error: Call to undefined method bbcode::bbcode_second_pass_img() in /home/specvnet/public_html/forum/includes/bbcode.php(112) : regexp code on line 1

Not sure what's going on. Added / modified the code letter for letter.
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

Re: [BETA] Auto Image Resize 0.0.2 (Non-JavaScript)

Post by MaidenFan »

Bawls wrote:Fatal error: Call to undefined method bbcode::bbcode_second_pass_img() in /home/specvnet/public_html/forum/includes/bbcode.php(112) : regexp code on line 1

Not sure what's going on. Added / modified the code letter for letter.
Are you sure you've added the second part of the MOD just before the "?>" tag at the end of the file? That error means like it's looking for the second-pass function and can't find it.
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
User avatar
JunglistPerfection
Registered User
Posts: 611
Joined: Mon Apr 09, 2007 11:58 pm
Location: Chicago, IL

Re: [BETA] Auto Image Resize 0.0.2 (Non-JavaScript)

Post by JunglistPerfection »

Didn't work for me. :cry:
User avatar
MaidenFan
Registered User
Posts: 43
Joined: Mon Dec 12, 2005 3:33 pm
Location: Aberystwyth, Wales, UK

Re: [BETA] Auto Image Resize 0.0.2 (Non-JavaScript)

Post by MaidenFan »

JunglistPerfection wrote:Didn't work for me. :cry:
If you delete the "@" just before the "getimagesize($url)" code inside the second-pass function you should get the PHP error message that's causing the script to fail. It could be that the "allow_fopen_url" option isn't turned on within your PHP installation, as detailed in the first post.

Either way, if you could post the error message it would be helpful :)
Personal Site & Blog | Last.fm
erno @ Bash.org wrote:I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
User avatar
JunglistPerfection
Registered User
Posts: 611
Joined: Mon Apr 09, 2007 11:58 pm
Location: Chicago, IL

Re: [BETA] Auto Image Resize 0.0.2 (Non-JavaScript)

Post by JunglistPerfection »

Ok, I did what you ask by take the @ out from"getimagesize($url)" and this is the I get:

Code: Select all

Fatal error: Call to undefined method: bbcode->bbcode_second_pass_img() in /includes/bbcode.php(112) : regexp code on line 1
I hope this helps solve the problem.

Return to “[3.0.x] Abandoned MODs”