PDA

View Full Version : [RELEASE vB2.0b2] Image size restriction hack


JWS
07 Mar 2001, 02:49
Okay, I don't know about the rest of you, but I was getting a little tired of images being WAY too huge in posts and blowing away the formatting of the tables. So, after collecting some code here and there and hacking the functions.php file we have the following hack. Please note that I'm not claiming for this to be the best code in the world, but after a couple of hours of debugging, it'll have to do -- you may optimize at will!

This hack will allow you to set the maximum width that you want an image to be and any pic in a signature or a post will be automatically sized to fit within this parameter. This does NOT resize the image graphic, but rather just figures out what the maximum "height" and "width" parameters should be on the IMG tag when displaying it. The images will still take as long to download since its the same larger graphic, but they'll be sized correctly at least.

This will only work on vBcode IMG tags!

Okay, here are the steps:

In function.php, in the bbcodeparse2() function, look for the following code:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


Replace this code with:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


Now, at the end of functions.php, add the following:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Note that in the function called imagereduction(), there is a setting for the "picsize". That should actually be the maximum width that you want for your pictures to be. The point of the imagereduction() function is to determine the proportions correctly based on the image's size.

Also note that both of these functions are someone else's and the GetURLImage() function will not be necessary with PHP 4.0.5 comes out because the PHP GetImageSize() function will accept URLs.

07 Mar 2001, 04:34
What I'd like is something that will also check the file size, and if it is over a set limit, it will display a link to the image rather than the image itself. This could be used in conjunction with the above hack. First the image is checked for file size; if it is too big, it is made into a link. If the file size is OK, then its width is checked and processed by the above hack.

07 Mar 2001, 12:17
Something I'll add about this hack is that it DOES slow down page loads a little since it's basically requesting each image once before the page is even loaded. Graphic-intensive pages could take a little longer.

JJR512: The hack you mentioned is an easy one, however, it has the same speed effect I'm mentioning here -- it requests the file once via HTTP, figures out its size, and then does something with it. If you're willing to take a little bit of a response decrease, I'll be glad to send you the code.

07 Mar 2001, 13:24
Yeah, please send it, and I'll see what kind of an effect it does have.