I must store/retrieve a lot of images to make use of during my program. Each image is small: a symbol 50x50, and they all have connected a string the path the icon relates to.

Being that they are so small I believed if there's some library which enables to keep these in one file. I will have to store both image and also the path string.

I'm not sure if pickle is really a possible choice - I additionally learned about a lot more complicated libraries for example HDF5...

interesting help!

alessandro

The sqlite3 module within the standard library would get the job done nicely.

The photos are small at 2500 bits per color plane plus they a may be easily saved as blob records within the database (that is saved like a single file).

Is not this maybe simpler? (stolen here http://bytes.com/topic/python/answers/44238-pickle-image)

import Image, pickle, cStringIO

i = open('button_home.gif', 'rb')
i.seek(0)
w = i.read()
i.close()
dic = {'1':w,'2':w,'3':w,'4':w}

F=open('allicons.dat','w')
pickle.dump(dic,F)
F.close()

#Ok now you take your pickled string and unpickle your object and select
#the item you want and put it in a cStringIO or StringIO so we can open
#it directly with PIL.
F=open('allicons.dat','r')
o=pickle.load(F)
F.close()

one_im = o['1']
c = cStringIO.StringIO()
c.write(one_im)
c.seek(0)
im = Image.open(c)
im.show()

You can pickle a dict that affiliates filenames to byte strings of RGBA data.

Presuming you've loaded the look with PIL, make certain they've the same size and color format. Develop a dict with images[filename] = im.tostring() and dump() it with pickle. Use Image.fromstring using the right size and mode parameters to have it back.