PDA

View Full Version : Not that you need my advice, but I'll share it anyway... ;)


bira
Thu 6th Dec '01, 3:29am
Hi,

I've previously advocated for adding a process to get the size (width dimension) of images posted via [img ][ /img], so we can rescale large images to thumbnails or some other reasonable size.

I'm writing now to suggest you don't do it :)

I've spent the last couple of days running extensive testing on various solutions to getting image size for pictures.

The only way to do it, really, it to explode $bbcode once with [img ], then run a loop on the result array -- odd keys only (1,3,5 etc) -- and explode each of these by [/img ] to grab the image url and thereafter image size.

I've minimized the loop as much as possible (I'll spare you of the code unless you're interested) and after that ran QA on anything from a short, image-less thread, to a thread with dozens of posts, each with an average of 2-3 images.

The result is a significant slowness of the page loading. I would say running the process for each image takes up about 0.5sec on average. In a thread with 40 posts per page, with 2 images per post, you are looking at an addition of over 30 seconds to the parsing of the page by php!!!

There are other issues:

1) getting image size of remote files also depends on quality of connection to the hosting server of the picture. With poor connection, it can seriously slow down the loading of the page, to the extent that I even got at times a php max execution time exceeded error.

2) getimagesize on remote files was added only as of 4.0.5. I'm not sure all vB users have 4.0.5 and up.

3) resizing the image to a thumbnail or smaller size does not save download time for the users -- the full image is still downloaded, so in effect a 2000x2000 image, weighing 1mb, could be displayed as 200x200 -- but it would still be 1mb of download.

In short, there are heaps and heaps of disadvantages in running such procedure. Processing showthread is not a quickie job as it is, but at the moment, on my development server, it runs on an average of <1 second parse+mysql work time. With the addition of the getimagesize routine, as I said, it could go well beyond the max execution time (which, unless you edited php.ini, is 30 seconds by default).

Anyhow, I felt compelled to share this because I was one to ask for this feature - and I wanted to let you know I'm now begging you not to add it :D

Cheers,

Bira

Mas*Mind
Thu 6th Dec '01, 3:43am
Not that I don't agree with you that it probably will cost too much resources, but you the way you do it is much too complicated... You can do it too with the preg_replace method in combination with the /e modifier. I don't know how much it will increase the process, but it probably will...

bira
Thu 6th Dec '01, 5:36am
I wasn't able to figure out how to do it. I kept getting an error that the function I had for getting the size could not be redeclared. But that's a side-issue :)

In any event, whether you take the long and winding route or the highway, you're still gonna lost most of your parsing time on the GetImageSize station :D

amykhar
Thu 6th Dec '01, 10:48am
All I really want is the ability to add width and height and align and hspace and vspace to the img vbb code tags. I can then edit user posts and make things look right. I don't need it to be dynamic.

Amy

bira
Thu 6th Dec '01, 7:18pm
Amy you mean a bbcode that looks like:

[img width=x height=x hspace=x vspace=x][ / img] ?


You can create that in the custom code I should think

tubedogg
Thu 6th Dec '01, 9:50pm
Not without hacking...currently vB Codes can only handle one attribute per tag.

Razgo
Mon 29th Apr '02, 1:16am
this was the closest thing I could find doing a search.

So my understanding is at present time we cannot resize an image in a post?

I was trying to do it before when i relized there is no option/command line to use?

other forums seem to use it without any noticible slow down of the pages and is something that comes in very handy.

thanks.

Mas*Mind
Mon 29th Apr '02, 3:06am
To rethink of this idea:

Maybe it's a good idea to parse it when saving the message? This way it only has to be done once....s

SysMom
Fri 3rd May '02, 10:21pm
You should be able to dynamically resize an image with just *one* param. If you specify the size of the horizontal and do not specify the vertical at all, it will display proportionately to the horizontal specification in the browser.

I know that won't help your vspace and hspace, but it might help some, at least.

-deb