The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Resize large [IMG] images and link them to original Details »» | |||||||||||||||||||||||||||
Resize large [IMG] images and link them to original
Developer Last Online: Aug 2013
This mod should resize [IMG] images wider than 'max_width' and link them to their original size. Not very well tested, i'm hoping for some feedback/suggestions. I have tested in firefox/IE latest versions and it seems to work fine. Should be a pretty quick install.
INSTALL: 1) Edit /includes/class_bbcode.php around line 1879 for me. Look for: Code:
return '<img src="' . $link . '" border="0" alt="" />'; Code:
return '<img src="' . $link . '" border="0" alt="" class="img_tag" />'; Code:
<if condition="THIS_SCRIPT == 'showthread'"> <script type="text/javascript"> max_width = 700; if(document.documentElement.outerHTML == null) { HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) { var r = this.ownerDocument.createRange(); r.setStartBefore(this); var df = r.createContextualFragment(sHTML); this.parentNode.replaceChild(df, this); }); } function resizeImages() { for(var i=0; i<document.images.length; i++) { var img = document.images[i]; if(img.className == "img_tag") { if(img.width > max_width) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img width = "' + max_width + '" src="' + img.src + '" border=0 alt="" /></a>'; img.outerHTML = strNewHTML; } } } } if (window.addEventListener) { window.addEventListener('load', resizeImages, false); } else if (window.attachEvent) { window.attachEvent('onload', resizeImages); } else { window.onload = resizeImages; } </script> </if> Show Your Support
|
Comments |
#42
|
||||
|
||||
Quote:
Thanks |
#43
|
|||
|
|||
Quote:
All you need to do is add a new variable at the top under max_width called max_height, and then add an else if statement to the resizeImages function so that it also checks maximum height and resizes. Seems to work without any problems on IE7 and Firefox, haven't tested it extensively yet. The completed modified code to get this hack working with all the bells and whistles is this: Edit /includes/class_bbcode.php as normal, that is changing: Code:
return '<img src="' . $link . '" border="0" alt="" />'; Code:
return '<img src="' . $link . '" border="0" alt="" id="img_tag" />'; Code:
<if condition="THIS_SCRIPT == 'showthread'"> <script type="text/javascript"> max_width = 500; max_height = 400; if(document.documentElement.outerHTML == null) { HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) { var r = this.ownerDocument.createRange(); r.setStartBefore(this); var df = r.createContextualFragment(sHTML); this.parentNode.replaceChild(df, this); }); } function resizeImages() { for(var i=0; i<document.images.length; i++) { var img = document.images[i]; if(img.id == "img_tag") { if(img.width > max_width && ((max_width / img.width) * img.height) < max_height) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img width = "' + max_width + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } else if(img.height > max_height && ((max_height / img.height) * img.width) < max_width) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img height = "' + max_height + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } else if(img.height > max_height && img.width > max_width) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img height = "' + max_height + '" img width = "' +max_width + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } } } } if (window.addEventListener) { window.addEventListener('load', resizeImages, false); } else if (window.attachEvent) { window.attachEvent('onload', resizeImages); } else { window.onload = resizeImages; } </script> </if> Here's some screenshots of how it looks and works on my forums: Maximum width (set to 500 on my forums) enforced without affecting smaller images, note the neat notification under each image, so users won't be confused: When the image is clicked it opens the full-sized image in a new window. Hovering the mouse over the image shows the 'Click to enlarge' alt text. Maximum height (set to 400 on my forums) enforced again without any problems, and again with the notification: Thanks for creating this code in the first place nsanden, and with some subtle modifications it seems to meet all my needs now, so I've clicked Install |
#44
|
|||
|
|||
Thanks for this hack ... *install* ... i like this one
I includes all the suggested changes, e.g. to resize also the hight of the images, but it doesn't seem to work correctly. I can't describe it, but what happens if the width AND the hight have to be resized? In my forum it seems that only one is resized .. .the hight OR the width? Some images are only resized in the width, not in the hight. Others are sized perfectly ... Any idea? Edit: To show what I tried to explain, please see this thread of my forum http://www.auftrab.de/Forum//showthread.php?t=336. In the first threadbox, the images are resized, in the second one they have the original size... |
#45
|
|||
|
|||
Actually after a moment's thought I realized that my max_height "fix" isn't really a true fix. All it does is check to see if a picture meets the maximum width first or the maximum height - one or the other, not both.
That is, if a picture is both wide and tall, it only resizes the width not the height because that's the first thing it checks. I'll test out some more code and post the full solution shortly. /EDIT: OK, I believe I've solved this problem. I just included another else if statement and modified the first two statements to check more throughly. This should cover all situations and should keep the correct aspect ratio for resized images. Code:
<if condition="THIS_SCRIPT == 'showthread'"> <script type="text/javascript"> max_width = 500; max_height = 400; if(document.documentElement.outerHTML == null) { HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) { var r = this.ownerDocument.createRange(); r.setStartBefore(this); var df = r.createContextualFragment(sHTML); this.parentNode.replaceChild(df, this); }); } function resizeImages() { for(var i=0; i<document.images.length; i++) { var img = document.images[i]; if(img.id == "img_tag") { if(img.width > max_width && ((max_width / img.width) * img.height) < max_height) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img width = "' + max_width + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } else if(img.height > max_height && ((max_height / img.height) * img.width) < max_width) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img height = "' + max_height + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } else if(img.height > max_height && img.width > max_width) { var strNewHTML = '<a href="' + img.src + '" target="_blank"><img height = "' + max_height + '" img width = "' +max_width + '" src="' + img.src + '" border=0 alt="Click to enlarge" /></a><br /><FONT SIZE=1>Image automatically resized to meet Image Guidelines - Click to enlarge</font>'; img.outerHTML = strNewHTML; } } } } if (window.addEventListener) { window.addEventListener('load', resizeImages, false); } else if (window.attachEvent) { window.attachEvent('onload', resizeImages); } else { window.onload = resizeImages; } </script> </if> |
#46
|
|||
|
|||
Thanks a lot for helping ... That's what I thought it would do ... but I'm very unexperienced in coding, so it was just a guess. Promise to wait patiently
|
#47
|
|||
|
|||
Quote:
EDIT: It's funny ... in some other threads in my forum the images are resized in width AND hight, only in the thread I posted it doesn't seem to work ... ?? |
#48
|
|||
|
|||
Try again, I just updated the code while you were testing it. Check my previous post. I missed some basic checks and I had to fix some things. Make sure to copy and paste the entire new code over your existing one in headinclude. It should work properly now.
|
#49
|
|||
|
|||
Hmm, just overwrote it again ... but please have a look http://www.auftrab.de/Forum/showthread.php?t=336 ... in the first thread it's ok, in the second one nothing happend ...
but anyway ... thanks a lot for your help ... |
#50
|
|||
|
|||
Looks to be working fine for me - make sure to press CTRL+F5 on your browser to refresh all the code which is being displayed. Also which browser are you using? It works for me in Internet Explorer 7 and Firefox.
|
#51
|
|||
|
|||
Thanks a lot, that may be the issue ... I'm in the office and there we have IE 6.0 ... :-) ... thanks for your help :-)
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|