flask-thumbnails-s3
An extension to create image thumbnails on Amazon S3 (or on local storage) with the Flask framework, based on flask-thumbnails.
Installation
Install with pip:
Run pip install flask-thumbnails-s3
Add Thumbnail to your extension file:
from flask_thumbnails_s3 import Thumbnail
app = Flask(__name__)
thumb = Thumbnail(app)
Add MEDIA_FOLDER and MEDIA_URL in your settings, as well as various S3-related values:
app.config['MEDIA_FOLDER'] = '/home/www/media'
app.config['MEDIA_URL'] = '/media/'
app.config['THUMBNAIL_S3_STORAGE_TYPE'] = 's3'
app.config['THUMBNAIL_S3_BUCKET_NAME'] = 'bucket-foo'
app.config['THUMBNAIL_S3_ACCESS_KEY_ID'] = 'key-here'
app.config['THUMBNAIL_S3_ACCESS_KEY_SECRET'] = 'secret-here'
app.config['THUMBNAIL_S3_USE_HTTPS'] = True
app.config['THUMBNAIL_S3_STATIC_ROOT_PARENT'] = '/path/to/project/root/'
Example usage
Use in Jinja2 template:
<img src="{{ 'image.jpg'|thumbnail('200x200', storage_type='s3', bucket_name='bucket-foo') }}" alt="" />
<img src="{{ 'image.jpg'|thumbnail('200x200', crop='fit', quality=100) }}" alt="" />
For a complete, working Flask app that demonstrates flask-thumbnails-s3 in action, have a look at flask-s3-save-example.
Options
crop='fit' returns a sized and cropped version of the image, cropped to the requested aspect ratio and size, read more.
quality=XX changes the quality of the output JPEG thumbnail, default 85.
Develop and Production
Production
In production, you need to add media directory in you web server.
Develop
To service the uploaded files need a helper function, where /media/ your settings app.config['MEDIA_URL']:
from flask import send_from_directory
@app.route('/media/<regex("([\w\d_/-]+)?.(?:jpe?g|gif|png)"):filename>')
def media_file(filename):
return send_from_directory(app.config['MEDIA_THUMBNAIL_FOLDER'], filename)
Option settings
If you want to store the thumbnail in a folder other than the MEDIA_FOLDER, you need to set it manually:
app.config['MEDIA_THUMBNAIL_FOLDER'] = '/home/www/media/cache'
app.config['MEDIA_THUMBNAIL_URL'] = '/media/cache/'
Acknowledgements
Much of the code here is based on flask-thumbnails by Dmitriy Sokolov:
https://github.com/silentsokolov/flask-thumbnails
Many thanks to the author and contributors of flask-thumbnails, for the foundation of this codebase, and for the generous license terms that allow forks like this.
Metadata
Release files for flask-thumbnails-s3 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_thumbnails_s3-0.1.5-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for flask_thumbnails_s3-0.1.5-py2.py3-none-any.whl |
Release files / flask_thumbnails_s3-0.1.5-py2.py3-none-any.whl
| Download URL | flask_thumbnails_s3-0.1.5-py2.py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
fbb5c3788d07977e632e6baf24e44d3a9f154ba156fa5e8966b61fde44cb2399
|
|
BLAKE2b-256 checksum How to use checksums |
359ac37532b6eee4f33e462d215d18330e801588c63092ad806d5fe844214630
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for flask-thumbnails-s3 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.