digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Website and Server Troubleshooting (https://www.digitalfaq.com/forum/web-tech/)
-   -   Resize displayed images in vBulletin 3.x, [IMG] bbcode hack (https://www.digitalfaq.com/forum/web-tech/3152-resize-displayed-images.html)

admin 06-01-2011 04:20 AM

Resize displayed images in vBulletin 3.x, [IMG] bbcode hack
 
Forums like The Digital FAQ are designed to a fixed width, so when somebody uploads an image that is too large for our design, it causes the page to stretch, which in turns creates vertical scroll bars, and tends to botch up the clean design. This only happens on images/photos linked with the IMG bbcode, and not properly attached to the forum.

Site note: Ideally, we never want our users to hotlink images to other sites anyway! (Why? Well, those other sites cannot be trusted! We want to archive information here forever, for the benefit of all readers now and far into the future. If a hotlinked image breaks, the post could become useless. There's also the ethical dilemma of bandwidth theft.)

Anyway, vBulletin 3.x can be hacked pretty easily to resize photos:


Step 1 -- Open %forumpath%\includes\class_bbcode.php

Step 2 -- Locate this text:
PHP Code:

        return '<img src="' .  $link '" border="0" alt="" />'

Step 3 -- Replace with this text:
PHP Code:

//        return '<img src="' .  $link . '" border="0" alt="" />';
        
return '<img src="' .  $link '" onload="if(this.width > 800) {this.width=800;this.alt=\'Click here to see a large version\';}" onmouseover="if(this.alt) this.style.cursor=\'pointer\';" onclick="if(this.alt) window.open(\'' $link '\');" border="0" />'

Note the image size. In our case, it's 800. Change it to whatever you would like.

Yes, we also suggest commenting out old default code (the "//" marks) and not deleting it!

When the page first loads, the image will be full sized, and resize happens on pageload completion. If your Internet connection is fast, it will be only a portion of a second. If the image is far down the page, you might not even know it's happening. If the page loads slow -- which may happen due to the slowness of the site where the images are linked from!!! -- then you'll see it load big, then shrink down again. So it's not 100% perfect, but it's better than the alternatives: sloppy vB.org plugins, shoddy template hacks, or simply disabling IMG bbcode entirely. Some of those plugins/mods may actually break your database! (It happens to us in 2009, forcing a db restore from the backup that was taken just prior to the plugin install. Hint: ALWAYS back up your database before "hacking" your own site code!)

This may or may not work in vBulletin 4.x. From what I've seen, this may finally be integrated into the default core. (FINALLY!)

Again, please attach files. :o


All times are GMT -5. The time now is 08:35 AM

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.