During my web application i am using MongoDB GridFS to keep user submitted images.

The relaxation from the website is handled by MySQL.

Inside a photo table (in mysql) I've three fields for storing the MongoId from the file object.

  • small
  • medium
  • large

And So I store three versions from the image. Small, medium and enormous.

My real question is, sometimes i'll want to use a thumbnail more compact compared to 'small' version from the image (i.e. inside a widget box, message avatars etc.) or i'll want to use a slighly more compact version from the medium image.

So my question, wouldn't it easier to just store one image within the GridFS system after which have one area within the photo table storing the MongoID after which produce a script that resizes the look quickly (i.e. http://localhost/image/fetch/?re-size=50

Otherwise, during my db i'll need thumbnail_50, thumbnail_100, medium_300, medium_400 etc. etc.

What will be the implications of heading down the on-the-fly re-size route? could it be a poor or advisable? How would you react?

Thanks.

Resizing quickly can lead to much more CPU strain on your server than resizing to a number of dimensions once, and storing the outcomes. However, resizing in advance may lead to a bigger group of data to become saved in GridFS. Quite simply, it is a tradeoff.

You could look at a hybrid approach, in which you re-size quickly but save the outcomes to GridFS to ensure that you don't have to re-size anyone image to some given size more often than once.

It's also wise to realize that HTML and CSS allow various choices for manipulating the displayed size a picture. For instance:

<img src="/path/to/image.jpg" width="50"/>

Can lead to a picture scaly proportionally to 50 pixels wide (in many modern browsers, anyway). You may also make use of the width and max-width CSS qualities to manage image size.

Personally, and knowing nothing concerning the volume or quality from the images you will be storing, I'd most likely re-size when images are added -- quite simply, go ahead and take page speed and CPU load hit once -- after which serve the different dimensions from GridFS, using max-width to manage the on-display size if your slightly different dimensions are needed in a single particular situation.

i'd get nearest size after which process it client size by javascript