flask-thumbnails
A simple extension to create a thumbs for the Flask
Installation
Use your favorite Python package manager to install the app from PyPI, e.g.
Example:
pip install flask-thumbnails
Add Thumbnail to your extension file:
from flask import Flask
from flask_thumbnails import Thumbnail
app = Flask(__name__)
thumb = Thumbnail(app)
Add THUMBNAIL_MEDIA_ROOT and THUMBNAIL_MEDIA_URL in your settings:
app.config['THUMBNAIL_MEDIA_ROOT'] = '/home/www/media'
app.config['THUMBNAIL_MEDIA_URL'] = '/media/'
Example usage
Use in Jinja2 template:
<img src="{{ 'image.jpg'|thumbnail('200x200') }}" alt="" /> <img src="{{ 'image.jpg'|thumbnail('200x200', crop='fit', quality=100) }}" alt="" />
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 90.
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['THUMBNAIL_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['THUMBNAIL_MEDIA_THUMBNAIL_ROOT'], filename)
Option settings
If you want to store the thumbnail in a folder other than the THUMBNAIL_MEDIA_THUMBNAIL_ROOT, you need to set it manually:
app.config['THUMBNAIL_MEDIA_THUMBNAIL_ROOT'] = '/home/www/media/cache'
app.config['THUMBNAIL_MEDIA_THUMBNAIL_URL'] = '/media/cache/'
app.config['THUMBNAIL_STORAGE_BACKEND'] = 'flask_thumbnails.storage_backends.FilesystemStorageBackend'
app.config['THUMBNAIL_DEFAULT_FORMAT'] = 'JPEG'
Migrate 0.X to 1.X
Since version 1.X all settings have a prefix THUMBNAIL_. Example: MEDIA_ROOT -> THUMBNAIL_MEDIA_ROOT.
Metadata
Release files for flask-thumbnails 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask-thumbnails-1.1.1.tar.gz | 6.6 kB | Without provenance | Details for flask-thumbnails-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_thumbnails-1.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for flask_thumbnails-1.1.1-py2.py3-none-any.whl |
Total release size: 13.4 kB
Release files / flask-thumbnails-1.1.1.tar.gz
| Download URL | flask-thumbnails-1.1.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b2f710f36137d86e0b6e5c64a9ba45b39212ef6b9525e3f2fca75e26d96f0b4
|
|
BLAKE2b-256 checksum How to use checksums |
ae8f6ee01c5b991eafa9e94bd399dd21e07d1c646cb5726b5589b61e2545abc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / flask_thumbnails-1.1.1-py2.py3-none-any.whl
| Download URL | flask_thumbnails-1.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f3891426f40adce0ba02210c28d8cb4b40a4627902622ad3f5043e24fa6e0800
|
|
BLAKE2b-256 checksum How to use checksums |
344c607cdb83395297d9a1f040c40ab10db296e82b63da3698a256d8a75aeb26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for flask-thumbnails 1.1.1
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.