Ah, well getting images OUT of a database is a good thing :-)
I suggest you use a scheme like squid uses; create a master directory, with a number of subdirectories, that each have up to 255 subdirectories.
That way you can store X times 255 files.
If you need more you can add more subdirs in the first layer, giving you up to 255255=65k files.
Need more? add a layer and you can go to 255255*255=16.5M files and still have only 255 files per dir (very fast)
That will take some fiddling with a script, but you can store the new location of the files in the database so you won't loose track of where the images are.