Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Auto resize Huge images for [IMG] bbcode Details »»
Auto resize Huge images for [IMG] bbcode
Version: 1.00, by 007pig 007pig is offline
Developer Last Online: Jan 2011 Show Printable Version Email this Page

Version: 3.0.3 Rating:
Released: 08-23-2004 Last Update: Never Installs: 44
 
No support by the author.

I find lots of people are looking for [IMG] hack. So i share mine now.

The hack modifies only a few lines and the images are resized automaticly by javascript.

Open functions_bbcodeparse.php

Search:
PHP Code:
function handle_bbcode_img_match($link)
{
    
$link strip_smilies(str_replace('\\"''"'$link));

    
// remove double spaces -- fixes issues with wordwrap
    
$link str_replace('  '''$link);

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

Replace with:
PHP Code:
function handle_bbcode_img_match($link)
{
    global 
$vboptions;
    
    
$link strip_smilies(str_replace('\\"''"'$link));

    
// remove double spaces -- fixes issues with wordwrap
    
$link str_replace('  '''$link);

    if (
$vboptions['legacypostbit'])
    {
        return 
'<a href=' $link ' target="_blank"><img src="' $link '" onload="if(this.width>screen.width-255) {this.width=screen.width-255;this.alt=\'Full View\';}" onmouseover="if(this.alt) this.style.cursor=\'hand\';" border="0"></a>';
    }
    else
    {
        return 
'<a href=' $link ' target="_blank"><img src="' $link '" onload="if(this.width>screen.width-80) {this.width=screen.width-80;this.alt=\'Full View\';}" onmouseover="if(this.alt) this.style.cursor=\'hand\';" border="0"></a>';
    }

All done. Enjoy!

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #42  
Old 05-19-2005, 02:07 PM
SVTBlackLight01's Avatar
SVTBlackLight01 SVTBlackLight01 is offline
 
Join Date: Jan 2003
Location: Texas
Posts: 504
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by buro9
This one resizes on the client using JavaScript appended to each image tag, whereas the other one (the one you quoted) uses server fetch requests to get the image and check the size and adjusts the tag as applicable.

This hack will still load pages slowly for the client, but the layout will be fine. It will be fast for the server, slow for the browser.

That hack will still load pages slowly for the client, and the layout will be fine. But it will be slow for the server, fast for the browser.

May I make a suggestion about this hack though? Perhaps another method?

Instead of adding JavaScript to every IMG tag within every post, and firing that many onloads... why not just add javascript to your headinclude template that parses all images onload?

Example... Put this in your headinclude... and don't bother hacking any vBulletin files:
HTML Code:
<script type="text/javascript">
function resizeImages() {
  if (document.images) {
    var mw = 800;
    var mh = 800;
    for (var ii = 0; ii < document.images.length; ii++) {
      var i = document.images[ii];
      var iw = i.width;
      var ih = i.height;
      if (ih > iw && ih > mh) {
        i.style.height = mh + 'px';
      } else if (iw > mw) {
        i.style.width = mw + 'px';
      }
    }
  }
}
if (window.addEventListener) {
  window.addEventListener('load', resizeImages, false);
} else if (window.attachEvent) {
  window.attachEvent('onload', resizeImages);
} else {
  window.onload = resizeImages;
}
//-->
</script>
mw = maximum width in pixels.
mh = maximum height in pixels.

I've got mine set to 800 x 800, but you could put what you want in there.

Any img on the page will be resized to fit that area.

Of course, the end user still has to download them, but this resolves the problem with the script part going through to edits and quotes, and is also an easier install.

You don't have to use this version, but it's simpler methinks.
I tried this method, and it works great. A great example can be found on this page. Using the server-side resizing hack. This page would just lock up.

Also, I didn't want it to affect other parts of the site, so I used this conditional:
Code:
<if condition="THIS_SCRIPT == 'showthread'">
</if>
Thanks, buro9!
Reply With Quote
  #43  
Old 05-21-2005, 08:36 PM
lefthome's Avatar
lefthome lefthome is offline
 
Join Date: Feb 2005
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works great in 3.07 but I installed the headinclude...
Reply With Quote
  #44  
Old 05-29-2005, 10:26 PM
mustang_lex mustang_lex is offline
 
Join Date: May 2005
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:

function handle_bbcode_img_match($link)
{
global $vboptions;

$link = strip_smilies(str_replace('\\"', '"', $link));

// remove double spaces -- fixes issues with wordwrap
$link = str_replace(' ', '', $link);

if ($vboptions['legacypostbit'])
{
return '<a href=' . $link . ' target="_blank"><img src="' . $link . '" onload="if(this.width>screen.width-900)

{this.width=screen.width-900;this.alt=\'Full View\';}" onmouseover="if(this.alt) this.style.cursor=\'hand\';"

border="0"></a>';
}
else
{
return '<a href=' . $link . ' target="_blank"><img src="' . $link . '" onload="if(this.width>screen.width-400)

{this.width=screen.width-400;this.alt=\'Full View\';}" onmouseover="if(this.alt) this.style.cursor=\'hand\';"

border="0"></a>';
}
}
I had to make my figures much higher to work, but it does work. Is there a way to add text to the bottom of the pic if its too big saying "Picture has been resized, click for full size pic" . just so some will know its been resized?

Thank you and cool hack btw :squareeyed:
Reply With Quote
  #45  
Old 05-29-2005, 11:47 PM
Allan's Avatar
Allan Allan is offline
 
Join Date: Jun 2003
Location: France
Posts: 1,513
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, click install
Reply With Quote
  #46  
Old 05-30-2005, 12:43 AM
mustang_lex mustang_lex is offline
 
Join Date: May 2005
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The only option I have is uninstall???
Reply With Quote
  #47  
Old 06-04-2005, 10:12 AM
MrD's Avatar
MrD MrD is offline
 
Join Date: Aug 2003
Location: Germany/NRW
Posts: 419
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,
Quote:
Originally Posted by buro9
This one resizes on the client using JavaScript appended to each image tag, whereas the other one (the one you quoted) uses server fetch requests to get the image and check the size and adjusts the tag as applicable.

This hack will still load pages slowly for the client, but the layout will be fine. It will be fast for the server, slow for the browser.

That hack will still load pages slowly for the client, and the layout will be fine. But it will be slow for the server, fast for the browser.

May I make a suggestion about this hack though? Perhaps another method?

Instead of adding JavaScript to every IMG tag within every post, and firing that many onloads... why not just add javascript to your headinclude template that parses all images onload?

Example... Put this in your headinclude... and don't bother hacking any vBulletin files:
HTML Code:
<script type="text/javascript">
function resizeImages() {
  if (document.images) {
    var mw = 800;
    var mh = 800;
    for (var ii = 0; ii < document.images.length; ii++) {
      var i = document.images[ii];
      var iw = i.width;
      var ih = i.height;
      if (ih > iw && ih > mh) {
        i.style.height = mh + 'px';
      } else if (iw > mw) {
        i.style.width = mw + 'px';
      }
    }
  }
}
if (window.addEventListener) {
  window.addEventListener('load', resizeImages, false);
} else if (window.attachEvent) {
  window.attachEvent('onload', resizeImages);
} else {
  window.onload = resizeImages;
}
//-->
</script>
mw = maximum width in pixels.
mh = maximum height in pixels.

I've got mine set to 800 x 800, but you could put what you want in there.

Any img on the page will be resized to fit that area.

Of course, the end user still has to download them, but this resolves the problem with the script part going through to edits and quotes, and is also an easier install.

You don't have to use this version, but it's simpler methinks.

i put it on my headinclude, but the script resized my logo too
Reply With Quote
  #48  
Old 06-06-2005, 04:48 AM
buro9 buro9 is offline
 
Join Date: Feb 2002
Location: London, UK
Posts: 585
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MrD
Hi,



i put it on my headinclude, but the script resized my logo too
Well it's just JavaScript

Within the for () {} loop, just add an exclusion... figure out what identifies your logo and if that is matched, skip the resize.
Reply With Quote
  #49  
Old 06-11-2005, 05:22 AM
LuBi LuBi is offline
 
Join Date: Oct 2001
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

SVTBlackLight01

Which image rezie script did you use? I saw you linked to one in the OTHER thread and it reseized then onclick made a popup with original image. Did you modify this buro9's code further or switch to the other mod?

http://www.modernengineuity.com/foru...hread.php?t=31

buro9

would it be possible to have this code generate the resized image as a link trageted to _blank in a new window with the original image in full size?

i install buro9's scrip with SVTBlackLight01 conditional and it works fine, but i'd like the option to click the image for the original.
Reply With Quote
  #50  
Old 06-13-2005, 07:22 AM
buro9 buro9 is offline
 
Join Date: Feb 2002
Location: London, UK
Posts: 585
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by LuBi
buro9

would it be possible to have this code generate the resized image as a link trageted to _blank in a new window with the original image in full size?

i install buro9's scrip with SVTBlackLight01 conditional and it works fine, but i'd like the option to click the image for the original.
It would be possible to add that link, but it would have an undesired effect.

What would happen is that when someone quoted or edited a post that had a large image, the additional code that I would have added via JavaScript would dribble through to the editor window or be stripped... this is according to vBulletin's internal stuff that basically reduces to URL tags (no knowledge of target), etc.

What I think I'm going to aim for after 3.5 is released is something far more nefarious.

If an image is detected, I'll resize it on the screen, but I'll also fire off an AJAX request to a custom web service that will edit the post and convert the offending IMG tag to a URL tag The image gets stripped and the link will appear instead.

Far more evil, far more effective... people WILL learn to reduce the image and attach if they want it to be visible
Reply With Quote
  #51  
Old 06-14-2005, 04:30 AM
SVTBlackLight01's Avatar
SVTBlackLight01 SVTBlackLight01 is offline
 
Join Date: Jan 2003
Location: Texas
Posts: 504
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by LuBi
SVTBlackLight01

Which image rezie script did you use? I saw you linked to one in the OTHER thread and it reseized then onclick made a popup with original image. Did you modify this buro9's code further or switch to the other mod?

http://www.modernengineuity.com/foru...hread.php?t=31
In that thread, what is posted there now is just smaller pics linked to the full size pics (from the gallery). I'm not using the other hack any more. It was causing pages with lots of pictures to completely lock up.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08320 seconds
  • Memory Usage 2,334KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (2)bbcode_html
  • (2)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete