Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rstit/flask-image-alchemy
SQLAlchemy Standarized Image Field for Flask
https://github.com/rstit/flask-image-alchemy
filestorage flask flask-extensions image-processing s3-storage thumbnails
Last synced: 3 months ago
JSON representation
SQLAlchemy Standarized Image Field for Flask
- Host: GitHub
- URL: https://github.com/rstit/flask-image-alchemy
- Owner: rstit
- Created: 2017-02-15T07:00:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T05:23:15.000Z (almost 2 years ago)
- Last Synced: 2024-10-09T17:23:05.266Z (4 months ago)
- Topics: filestorage, flask, flask-extensions, image-processing, s3-storage, thumbnails
- Language: Python
- Homepage:
- Size: 61.5 KB
- Stars: 18
- Watchers: 4
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Flask-ImageAlchemy
===============================
[![Build Status](https://travis-ci.org/rstit/flask-image-alchemy.svg?branch=master)](https://travis-ci.org/rstit/flask-image-alchemy)version number: 0.0.7
Overview
--------SQLAlchemy Standarized Image Field for Flask
Features
--------
- Storage backends (FileStorage, S3Storage)
- Thumbnails (wand)
- Flask Application Factory compatible
-Installation
--------------------To install use pip:
```bash
$ pip install Flask-ImageAlchemy
```Or clone the repo:
```bash
$ git clone https://github.com/rstit/flask-image-alchemy.git
$ python setup.py install
```
Usage
-----
#### SQLAlchemy Model
```python
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
)
```
#### Flask Settings
If you need S3Starage, set up config in your flask application:
```python
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 and custom `MEDIA_PATH`:
```python
MEDIA_PATH = "/var/www/assets/images/"
```
#### Usage in views
```python
u = User()
u.avatar = file # werkzeug.datastructures.FileStorage
u.save()
```
And you have access to thumbnails:
```python
u.avatar.url
u.avatar.thumbnail
u.avatar.thumbnail.url
u.avatar.thumbnail.path
```
#### Deleting imagesImplementing file deletion should be done inside your own applications using the `before_delete`
signal. Clearing the field if blank is true, does not delete the file. This can also be achieved
using `before_update` signals. This packages contains two event callback methods that handle file
deletion for all SdtImageFields of a model.```python
from flask_image_alchemy.events import before_update_delete_callback, before_delete_delete_callback
from sqlalchemy.event import listen
listen(User, 'before_update', before_update_delete_callback)
listen(User, 'before_delete', before_delete_delete_callback)
```TODO
------------
* Validators (MinSizeValidator, MaxSizeValidator)
* Flask-Admin widget
* Coverage
* Docs Page
* Async Jobs (Image Processing)