[page-speed-discuss] Specify Image Dimensions VS server speed

3 views
Skip to first unread message

Stephou

unread,
Apr 18, 2010, 3:12:01 PM4/18/10
to page-speed-discuss
Hi,

I have a bunch of pages that display thumbnails of images uploaded by
the users and I was wondering what is the best thing to do between :

1) Use getimagesize() in PHP for each thumbnail on the page and
include the image dimensions in the html of the page being displayed.
This will be better for the user because no browser redraw will occur
but slows down the page creation on the server side, (50 thumbnails *
time it takes for getimagesize() to execute) If i have many users at
the same time, many calls to getimagesize() happend on the server and
the server is then slower to respond to other requests.

2) Don't specify Image dimensions at all. The server does not have any
work to do, the user will see a browser-redraw when the pictures are
downloaded but might get the content faster since the server is less
busy.

3) Store the image size in a mysql database and retrieve it each time
a thumbnail is displayed. Better for the user (no browser-redraw), but
still slower than #2, because there is more data to process on the
server.

What option is the best? What is better between Speed and Perceived-
speed? Is there any other way of doing this?

Thanks!

--
You received this message because you are subscribed to the Google Groups "page-speed-discuss" group.
To post to this group, send email to page-spee...@googlegroups.com.
To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/page-speed-discuss?hl=en.

Sergey Chernyshev

unread,
Apr 18, 2010, 9:34:53 PM4/18/10
to page-spee...@googlegroups.com
I think the best way is to store the dimensions somewhere.

Whatever it's MySQL or not, is another story, more over, if you're using PHP, you might cache these values in APC for faster access. You can always generate static HTML too.

        Sergey

Sam Kerner

unread,
Apr 18, 2010, 11:22:49 PM4/18/10
to page-spee...@googlegroups.com
On Sun, Apr 18, 2010 at 3:12 PM, Stephou <step...@m-42.com> wrote:
> Hi,
>
> I have a bunch of pages that display thumbnails of images uploaded by
> the users and I was wondering what is the best thing to do between :
>
> 1) Use getimagesize() in PHP for each thumbnail on the page and
> include the image dimensions in the html of the page being displayed.
> This will be better for the user because no browser redraw will occur
> but slows down the page creation on the server side, (50 thumbnails *
> time it takes for getimagesize() to execute) If i have many users at
> the same time, many calls to getimagesize() happend on the server and
> the server is then slower to respond to other requests.
>
> 2) Don't specify Image dimensions at all. The server does not have any
> work to do, the user will see a browser-redraw when the pictures are
> downloaded but might get the content faster since the server is less
> busy.
>
> 3) Store the image size in a mysql database and retrieve it each time
> a thumbnail is displayed. Better for the user (no browser-redraw), but
> still slower than #2, because there is more data to process on the
> server.
>
> What option is the best? What is better between Speed and Perceived-
> speed? Is there any other way of doing this?
>
> Thanks!

You can avoid this problem if all your thumbnail images are known
to be the same size. You might consider resizing the thumbnails to a
known size when they are created. However, this won't work if
different images have different aspect ratios.

Keeping sizes in a database means you need to be sure the database
has the right sizes. I am not sure if #1 or #3 will be faster.

Sam

Stephou

unread,
Apr 19, 2010, 7:37:14 AM4/19/10
to page-speed-discuss
@sam : All the images have different aspect ratio, so I can't hardcode
the size in php.

@sergey : The pages with the thumbnails are dynamic, always changing,
so static html is not an option.

So far I think I will go with #3 because I already have to get the
photo descriptions from the MySQL database. I guess retreiving 2 more
colums from the database (image_X and image_Y) will not add that much
processing time...

But if someone has a better/faster idea let me know.

Thanks

Luca

unread,
Apr 19, 2010, 2:33:10 PM4/19/10
to page-speed-discuss
my php solution was to generate exact sized thumbnail (let's say
120x90) from original image and then store it in a folder images/
120x90/ as md5(filename)
that's happen on first call of the page as the 120x90 image was not
found ....next time just check that the file exist and serve
it ...pagespeed was happy about and me too
Reply all
Reply to author
Forward
0 new messages