In a web application I'm coding with Flask/SQLAlchemy, several of my models needs a "Photo" column type, which would handle storing the original image somewhere on the filesystem, and creating differents thumbnails size of the image. Ideally, I-d want something like:
class MyModel(Base):
id = Column(Integer, primary_key=True)
photo = Column(Photo(root="/path/to/photos/", formats={
"big" : "800x600",
"small" : "400x300",
"thumbnail": "100x75"
}))
and then, I could access URI/URL of file like this: model.photo.big etc...
So, my question is: how to add setters/getters on the model.photo object so that I can access URIS/URLS with the mentionned syntax ? By the way, if someone has a good tutorial/resource (other than the official doc) on user defined types with SQLAlchemy, I would be grateful if he could share it.
Thx.
Have you looked at Flask-Upload? It seems to be exactly what you were looking for.
It is not an answer but i think it is more convenient to use a structure like described at below link for image thumbnails:
http://flask.pocoo.org/mailinglist/archive/2011/1/26/pil-to-create-thumbnails-automatically-using-tag/#32aff91e05ba9985a49a76a4fb5338d7
Using a tag for creating thumbnails, you need to store only original image path in the db.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With