Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.5 > vBulletin 3.5 Add-ons

Reply
 
Thread Tools
Auto Resize Your Images 3.52 compliant Details »»
Auto Resize Your Images 3.52 compliant
Version: 1.00, by ggiersdorf ggiersdorf is offline
Developer Last Online: Aug 2012 Show Printable Version Email this Page

Version: 3.5.3 Rating:
Released: 12-27-2005 Last Update: Never Installs: 100
Template Edits
Code Changes  
No support by the author.

I was looking for some code that would allow an image over size x to be resized in IE, Firefox, and Opera. I tried all the variations out there without luck some would work in IE, some in Firefox, etc.. So I finally got a tweaked version of some old code that actually works flawless in IE, Firefox, and Opera. I have included it below, but It needs 1 final tweak that I'm hoping someone in the community can help with.

i am NOT taking credit for this hack, all I have done is tweak it to get it working for me..


This code has been updated as of 8:30pm with the clickable link built in now!

Step 1: Edit your class_bbcode.php file located in (root/includes)

find

PHP Code:
return '<img src="' .  $link '" border="0" alt="" />'
replace with the following.

PHP Code:
/* Start Image RESIZE */  

 
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower$_SERVER['HTTP_USER_AGENT'] ) : '';   
if (
stristr($navigator_user_agent"msie")) {   
    return 
'<a href="' .  $link '" target="_blank"><img src="' .  $link '" border="0" alt="" style="width: expression(this.width > 640 ? 480 : true);" /></a>';   
} else {   
    return 
'<a href="' .  $link '" target="_blank"><img src="' .  $link '" border="0" alt="" style="max-width: 730px;" /></a>';   
}    

/* End Image RESIZE */ 
you can play with the widths to get what you want working.

Show Your Support

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

Comments
  #52  
Old 01-18-2006, 01:33 AM
Marris Marris is offline
 
Join Date: Jul 2005
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is it possible to have this resize modification only affect bbcode parsing when it is called from the vBadvanced news.php module?

I'd like to do something like the following, but I'm not sure of the exact syntax and whether or not I can determine the page/script name within class_bbcode.php.

EDIT: Nevermind, I got it working 5 seconds after I posted with the following:

Code:
if (THIS_SCRIPT == 'adv_index'){  
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';   
if (stristr($navigator_user_agent, "msie")) {   
    return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="" style="width: expression(this.width > 640 ? 480 : true);" /></a>';   
} else {   
    return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="" style="max-width: 730px;" /></a>';   
}
} else {
return '<img src="' .  $link . '" border="0" alt="" />';  
}
Reply With Quote
  #53  
Old 01-18-2006, 11:04 PM
S@NL - BlackBik's Avatar
S@NL - BlackBik S@NL - BlackBik is offline
 
Join Date: Jul 2004
Location: Netherlands
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK guys,

Here is the last revision of my code. Finaly got it working:
Code:
	 /* Start hack Image RESIZE */  

		// Check to see if image exists
 		$link = str_replace(" " , "%20", $link);
 		$link = str_replace("&amp;" , "%26", $link);

		// Get host url name for fsockopen to see if server is reachable
		$img_host=str_replace('http://','',$link);
		$img_host=substr($img_host,0,strpos($img_host,'/'));

		// Check is server is reachable and timeout in 5 seconds if not
		if (@fclose(@fsockopen($img_host, 80, $fsockerr1, $fsockerr2, 5))) {
			// Check if image is on server
			if (@fclose(@fopen("$link", "rb"))) { 
				// Check image size and if oversize, change bbtag
				$img_width = getimagesize($link);
				if ($img_width[0] > 600) {
	 				$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';   
					if (stristr($navigator_user_agent, "msie")) {   
    					return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="width: expression(this.width > 600 ? 600 : true);" /></a>';   
					} else {   
    					return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="max-width: 600px;" /></a>';   
					}
				} else {
					return '<img src="' .  $link . '" border="0" alt="" />';
				}
			} else {
				// Image not found
				return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_link_broken'] . '</font></td></tr></table>';
			}
		} else {
			// Server is down
			return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_server_down'] . '</font></td></tr></table>';
		}
		
	/* End hack Image RESIZE */ 
//	/* Original code:		return '<img src="' .  $link . '" border="0" alt="" />'; */
What it does:
Check if the database server is online
Check if the image is available
Check the width of the image
If > 600 width, resize to 600 and place a link under it to click for the orginal image
It doesn't touch the image when =< 600 width.
The problem with not being able to cope with spaces or ampersands in the url is solved.

If you are gonna use this, be sure to add the three phrases.
You can costumize the width that you want as limit for resizing by changing the three instanses of "600" in the code to the limit you want.

I don't want to take credit for this code because I did nothing else than changing the existing code that was allready there

Enjoy
Reply With Quote
  #54  
Old 01-19-2006, 12:05 AM
Codeman05 Codeman05 is offline
 
Join Date: Oct 2002
Location: Tx
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

seems to make the pages take alot longer to load...or is it just me?
Reply With Quote
  #55  
Old 01-19-2006, 06:24 AM
apfparadise apfparadise is offline
 
Join Date: Jan 2005
Location: Northridge CA
Posts: 110
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by S@NL - BlackBik
.... and place a link under it to click for the orginal image
I dont see that in the code or on my site. Do you mean it makes image into a link? Or actual line of text under the image that says something like: "This image has been resized, please click on it to see the full version"? 'Cause that would be great, to make it easy for the members to know when it's resized.
Reply With Quote
  #56  
Old 01-19-2006, 11:26 AM
S@NL - BlackBik's Avatar
S@NL - BlackBik S@NL - BlackBik is offline
 
Join Date: Jul 2004
Location: Netherlands
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Codeman05
seems to make the pages take alot longer to load...or is it just me?
Yes, if you open a page with a lot of pictures, it can take longer.
That's because each picture is validated and that's a extra process in opening the page.
Pages with no pictures of just a few will not be affected.
Reply With Quote
  #57  
Old 01-19-2006, 11:35 AM
S@NL - BlackBik's Avatar
S@NL - BlackBik S@NL - BlackBik is offline
 
Join Date: Jul 2004
Location: Netherlands
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by apfparadise
I dont see that in the code or on my site. Do you mean it makes image into a link? Or actual line of text under the image that says something like: "This image has been resized, please click on it to see the full version"? 'Cause that would be great, to make it easy for the members to know when it's resized.
Sorry, but English is not my native language. I'm Dutch and sometimes it ain't easy to express exactly what you want to say.
With "under it" I meant that when you hoover over the picture you see a resize message and the cursor changes into a hand. Then you can click the picture for a larger image.

If you want this text litteraly under the picture, you might try this:

Find:
Code:
return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="width: expression(this.width > 600 ? 600 : true);" /></a>';   
} else {   
return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="max-width: 600px;" /></a>';   
}
and replace by:
Code:
return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="width: expression(this.width > 600 ? 600 : true);" /><br><br>' . $vbphrase['click_for_larger_image'] . '</a>';   
} else {   
return '<a href="' .  $link . '" target="_blank"><img src="' .  $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="max-width: 600px;" /><br><br>' . $vbphrase['click_for_larger_image'] . '</a>';   
}
I didn't test it but it should do the trick

Again, don't forget to add the vbphrases, or substitute in above code ' . $vbphrase['click_for_larger_image'] .' for hard coded text like "Click for larger image".
Reply With Quote
  #58  
Old 01-19-2006, 11:45 AM
S@NL - BlackBik's Avatar
S@NL - BlackBik S@NL - BlackBik is offline
 
Join Date: Jul 2004
Location: Netherlands
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by apfparadise
Also, I am not sure, but can it be made when the image is not available or the server times out for it to show an image? I created two images like this:



and



Can they be shown if there is no image?
I think this is your last issue and this should not be to difficult to address.
Find in the code of post #52 the next code:
Code:
// Image not found
				return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_link_broken'] . '</font></td></tr></table>';
			}
		} else {
			// Server is down
			return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_server_down'] . '</font></td></tr></table>';
		}
and change is to this:
Code:
// Image not found
				return '<img src="http://aquatic-photography.com/pics/noimage.gif" border="0" alt="" />';
			}
		} else {
			// Server is down
			return '<img src="http://aquatic-photography.com/pics/noserver.gif" border="0" alt="" />';
		}
I didn't test this either but i'm pretty sure it works
Reply With Quote
  #59  
Old 01-19-2006, 12:54 PM
A-handreas A-handreas is offline
 
Join Date: Oct 2002
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your code is good, but I have a lot of pictures in my forums. It took some seconds to saw the thread while the pictures are checked before the thread would be visible. The user think my forum is slow. Any chance to modify this, because I know the original code was f*cking fast
Reply With Quote
  #60  
Old 01-19-2006, 01:08 PM
S@NL - BlackBik's Avatar
S@NL - BlackBik S@NL - BlackBik is offline
 
Join Date: Jul 2004
Location: Netherlands
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry A-handreas, as I said before I'm not realy a coder. I just combined two pieces of code to make another one and succeeded (to my own suprise) to make that work.
I lowered the time-out variable on the @fsockopen() command from 5 to 2. That might speed things up a little.
But I'm not aware of php code that could do those checks faster.
Maybe some *real* coders know a quicker way.
Reply With Quote
  #61  
Old 01-19-2006, 06:36 PM
Puntoboy Puntoboy is offline
 
Join Date: Sep 2005
Location: Northampton UK
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so it this hack like what you get on invision power boards?

when someone posts and image linked from another site/gallery it will resize the image so it keeps the thread structure aligned?

if so, how do i insert this code? whats the final code that works?
Reply With Quote
Reply

Thread Tools

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 07:05 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.04425 seconds
  • Memory Usage 2,329KB
  • 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
  • (6)bbcode_code
  • (2)bbcode_php
  • (4)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
  • (4)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