version number: 0.0.7
SQLAlchemy Standarized Image Field for Flask
- Storage backends (FileStorage, S3Storage)
- Thumbnails (wand)
- Flask Application Factory compatible
To install use pip:
$ pip install Flask-ImageAlchemy
Or clone the repo:
$ git clone https://github.com/rstit/flask-image-alchemy.git
$ python setup.py install
Create model with StdImageField
storage = S3Storage()
storage.init_app(app)
class User(db.Model):
__tablename__ = 'example'
id = db.Column(db.Integer, primary_key=True)
image = db.Column(
StdImageField(
storage=storage,
variations={
'thumbnail': {"width": 100, "height": 100, "crop": True}
}
), nullable=True
)
If you need S3Starage, set up config in your flask application:
AWS_ACCESS_KEY_ID = "you-api-key"
AWS_SECRET_ACCESS_KEY = "you-secret-key"
AWS_REGION_NAME = "bucket-region"
S3_BUCKET_NAME = "bucket-name"
If you need filestorage with different MEDIA_PATH
MEDIA_PATH = "/var/www/assets/images/"
Then you can use image field
u = User()
u.avatar = file
u.save()
And you have access to thumbnails:
u.avatar.url
u.avatar.thumbnail
u.avatar.thumbnail.url
u.avatar.thumbnail.path
- Validators (MinSizeValidator, MaxSizeValidator)
- Flask-Admin widget
- Coverage
- Docs Page
- Async Jobs (Image Processing)