vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Auto Resize Your Images 3.52 compliant (https://vborg.vbsupport.ru/showthread.php?t=103915)

Marris 01-18-2006 01:33 AM

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="" />'; 
}


S@NL - BlackBik 01-18-2006 11:04 PM

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 :)

Codeman05 01-19-2006 12:05 AM

seems to make the pages take alot longer to load...or is it just me?

apfparadise 01-19-2006 06:24 AM

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.

S@NL - BlackBik 01-19-2006 11:26 AM

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.

S@NL - BlackBik 01-19-2006 11:35 AM

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".

S@NL - BlackBik 01-19-2006 11:45 AM

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:

http://aquatic-photography.com/pics/noimage.gif

and

http://aquatic-photography.com/pics/noserver.gif

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 :)

A-handreas 01-19-2006 12:54 PM

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

S@NL - BlackBik 01-19-2006 01:08 PM

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.

Puntoboy 01-19-2006 06:36 PM

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?


All times are GMT. The time now is 03:48 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01447 seconds
  • Memory Usage 1,768KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete