views:

896

answers:

6

What is the best format to store images in a database, such as binary,base64...etc, for optimal speed/size.

A: 

Binary.

Other than that, it's up to the uses of the images (quality, compression, etc.) in terms of whether you choose PNG, GIF, JPEG, TIFF, etc.

The use case will (should) drive the format more than the database.

Will Hartung
A: 

Most databases can store binary data in some way:

As for the image file format, that is a separate issue. Not sure if you were alluding to that problem. If you were, it usually doesn't matter between PNG, GIF and JPG other than JPG being a lossy format (the other two are lsosless), which is OK for photos and the like but not, say, for icons or text.

cletus
mysql or possibly ms sql
teh_noob
A: 

That depends alot on what the images are used for.

  • Avatars can just be compressed JPEGS
  • Images that will be manipulated via image processing software would be TIFF
  • Images on a photo site would be JPEG for viewing, TIFF for downloading.

We just need a bit more information. If the files are very large, store them in a directory with a link in the database.

gbrandt
+6  A: 

Microsoft's advice for SQL Server used to be, for speed and size, store images in the file system, with links in the database. I think they've softened their preference a bit, but I still consider it a better idea certainly for size, since it will take up no space in the database.

le dorfier
I agree with this sentiment. I'm unaware of any advantage to adding images directly to the database and then I have to deal with a database that's 10 gigs instead of 2 gigs. Ick.
Spencer Ruport
A: 

Blob's don't care what kind of image you fill them with, so really, the right choice is probably whatever requires the least post select processing before its used.

dicroce
+3  A: 

Blob is the answer for your question.

Instead of storing image to database directly you can store the image in hard disk And store the filename in database.I think this way is appropriate.Performance wise this is good.

BlackPanther