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