.. image:: https://github.com/silentsokolov/flask-thumbnails/workflows/build/badge.svg?branch=master
:target: https://github.com/silentsokolov/flask-thumbnails/actions?query=workflow%3Abuild+branch%3Amaster
.. image:: https://codecov.io/gh/silentsokolov/flask-thumbnails/branch/master/graph/badge.svg
:target: https://codecov.io/gh/silentsokolov/flask-thumbnails
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:
.. code:: python
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:
.. code:: python
app.config['THUMBNAIL_MEDIA_ROOT'] = '/home/www/media'
app.config['THUMBNAIL_MEDIA_URL'] = '/media/'
Example usage
-------------
Use in Jinja2 template:
.. code:: html
<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 <http://pillow.readthedocs.org/en/latest/reference/ImageOps.html#PIL.ImageOps.fit>`_.
``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']``:
.. code:: python
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:
.. code:: python
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``.
Raw data
{
"_id": null,
"home_page": "https://github.com/silentsokolov/flask-thumbnails",
"name": "flask-thumbnails",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
"maintainer_email": "",
"keywords": "",
"author": "Dmitriy Sokolov",
"author_email": "silentsokolov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ae/8f/6ee01c5b991eafa9e94bd399dd21e07d1c646cb5726b5589b61e2545abc9/flask-thumbnails-1.1.1.tar.gz",
"platform": "any",
"description": ".. image:: https://github.com/silentsokolov/flask-thumbnails/workflows/build/badge.svg?branch=master\n :target: https://github.com/silentsokolov/flask-thumbnails/actions?query=workflow%3Abuild+branch%3Amaster\n\n.. image:: https://codecov.io/gh/silentsokolov/flask-thumbnails/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/silentsokolov/flask-thumbnails\n\nflask-thumbnails\n================\n\nA simple extension to create a thumbs for the Flask\n\n\nInstallation\n------------\n\nUse your favorite Python package manager to install the app from PyPI, e.g.\n\nExample:\n\n``pip install flask-thumbnails``\n\n\nAdd ``Thumbnail`` to your extension file:\n\n.. code:: python\n\n from flask import Flask\n from flask_thumbnails import Thumbnail\n\n app = Flask(__name__)\n\n thumb = Thumbnail(app)\n\nAdd ``THUMBNAIL_MEDIA_ROOT`` and ``THUMBNAIL_MEDIA_URL`` in your settings:\n\n.. code:: python\n\n app.config['THUMBNAIL_MEDIA_ROOT'] = '/home/www/media'\n app.config['THUMBNAIL_MEDIA_URL'] = '/media/'\n\n\nExample usage\n-------------\n\nUse in Jinja2 template:\n\n .. code:: html\n\n <img src=\"{{ 'image.jpg'|thumbnail('200x200') }}\" alt=\"\" />\n <img src=\"{{ 'image.jpg'|thumbnail('200x200', crop='fit', quality=100) }}\" alt=\"\" />\n\n\nOptions\n~~~~~~~\n\n``crop='fit'`` returns a sized and cropped version of the image, cropped to the requested aspect ratio and size, `read more <http://pillow.readthedocs.org/en/latest/reference/ImageOps.html#PIL.ImageOps.fit>`_.\n\n``quality=XX`` changes the quality of the output JPEG thumbnail, default ``90``.\n\n\nDevelop and Production\n----------------------\n\nProduction\n~~~~~~~~~~\n\nIn production, you need to add media directory in you web server.\n\n\nDevelop\n~~~~~~~\n\nTo service the uploaded files need a helper function, where ``/media/`` your settings ``app.config['THUMBNAIL_MEDIA_URL']``:\n\n.. code:: python\n\n from flask import send_from_directory\n\n @app.route('/media/<regex(\"([\\w\\d_/-]+)?.(?:jpe?g|gif|png)\"):filename>')\n def media_file(filename):\n return send_from_directory(app.config['THUMBNAIL_MEDIA_THUMBNAIL_ROOT'], filename)\n\n\nOption settings\n---------------\n\nIf you want to store the thumbnail in a folder other than the ``THUMBNAIL_MEDIA_THUMBNAIL_ROOT``, you need to set it manually:\n\n.. code:: python\n\n app.config['THUMBNAIL_MEDIA_THUMBNAIL_ROOT'] = '/home/www/media/cache'\n app.config['THUMBNAIL_MEDIA_THUMBNAIL_URL'] = '/media/cache/'\n app.config['THUMBNAIL_STORAGE_BACKEND'] = 'flask_thumbnails.storage_backends.FilesystemStorageBackend'\n app.config['THUMBNAIL_DEFAULT_FORMAT'] = 'JPEG'\n\n\nMigrate 0.X to 1.X\n------------------\n\nSince version 1.X all settings have a prefix ``THUMBNAIL_``. Example: ``MEDIA_ROOT`` -> ``THUMBNAIL_MEDIA_ROOT``.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple extension to create a thumbs for the Flask",
"version": "1.1.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "344c607cdb83395297d9a1f040c40ab10db296e82b63da3698a256d8a75aeb26",
"md5": "47dc72391089f0dc4f05628bc3144c9f",
"sha256": "f3891426f40adce0ba02210c28d8cb4b40a4627902622ad3f5043e24fa6e0800"
},
"downloads": -1,
"filename": "flask_thumbnails-1.1.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "47dc72391089f0dc4f05628bc3144c9f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
"size": 6806,
"upload_time": "2023-02-03T10:34:56",
"upload_time_iso_8601": "2023-02-03T10:34:56.060328Z",
"url": "https://files.pythonhosted.org/packages/34/4c/607cdb83395297d9a1f040c40ab10db296e82b63da3698a256d8a75aeb26/flask_thumbnails-1.1.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ae8f6ee01c5b991eafa9e94bd399dd21e07d1c646cb5726b5589b61e2545abc9",
"md5": "1d280f2bb286e4a73701f68c35735142",
"sha256": "4b2f710f36137d86e0b6e5c64a9ba45b39212ef6b9525e3f2fca75e26d96f0b4"
},
"downloads": -1,
"filename": "flask-thumbnails-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "1d280f2bb286e4a73701f68c35735142",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
"size": 6567,
"upload_time": "2023-02-03T10:34:57",
"upload_time_iso_8601": "2023-02-03T10:34:57.657415Z",
"url": "https://files.pythonhosted.org/packages/ae/8f/6ee01c5b991eafa9e94bd399dd21e07d1c646cb5726b5589b61e2545abc9/flask-thumbnails-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-03 10:34:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "silentsokolov",
"github_project": "flask-thumbnails",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "flask-thumbnails"
}