1. Michael Bayer
  2. sqlalchemy


Clone wiki

sqlalchemy / UsageRecipes / StoringImages

One can store images in SQLite databases as numpy arrays. To convert to a PIL image object into an array:

import numpy as np
import Image


The dtype='uint8' is not truly necessary at this point, but PIL does odd things to the output in the next step when the array is not uint8.

In your model, make the image field a PickleType. It can store the numpy array.

To convert back to the image:

import numpy as np
import Image