11

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

7 Answers 7

9

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.

2
  • 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. Feb 7, 2009 at 2:31
  • 1
    Didn't SQL server 2008 add filestream support, allowing files to be accessed through the SQL server? Makes management a lot easier not having to keep your database and filesystem in sync with each other.
    – fabspro
    Aug 6, 2012 at 12:16
7

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.

1
  • Performance wise you think it is good? What is your use case?
    – fabspro
    Aug 6, 2012 at 12:18
5

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.

1

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.

0
0

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.

0

Use hdf5.

Similar to XML documents, HDF files are self-describing and allow users to specify complex data relationships and dependencies. In contrast to XML documents, HDF files can contain binary data (in many representations) and allow direct access to parts of the file without first parsing the entire contents.

Why hdf5?

-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.