Serialize Django's ImageField into imgproxy URLs for your Django REST Framework APIs to generate thumbnails.
Project description
Serialize Django’s ImageField into imgproxy URLs for your Django REST Framework APIs to generate thumbnails.
Important Notice
This package only provides the serializer class necessary to translate your ImageField to signed imgproxy URLs.
It does not provide anything to upload images to your object storage bucket. We suggest you use another Django storage backend library that’s able to communicate with your object storage solution, in particular we recommend the following:
Usage
0. Installation
You can easily install this package from PyPI with pip by doing:
pip install drf-imgproxy
1. Quickstart
In settings.py:
INSTALLED_APPS = [
...
'drf_imgproxy',
...
]
# Configure this to either of the following:
# - 's3' for Amazon S3, Minio and any other S3-compatible object
# storage
# - 'gs' for Google Cloud Storage
# - 'abs' for Azure Blob Storage
IMGPROXY_PROTOCOL = 's3'
# Set the following to the bucket name that imgproxy uses.
IMGPROXY_BUCKET_NAME = 'nerv_angel_captures'
# Set both of the following to the appropiate values of
# `IMGPROXY_KEY` and `IMGPROXY_SALT` of your imgproxy server.
IMGPROXY_KEY = 'ThisIsNotASecureKeyAtAll'
IMGPROXY_SALT = 'SeriouslyThisSaltIsVeryInsecure'
# Set the following to the publicly accessible URL of your imgproxy
# server.
IMGPROXY_HOST = 'https://imgproxy.infra.nerv.tld'
# Set the following variable to the available resolutions your API
# provides.
#
# The format is `(<width>, <height>)`.
IMGPROXY_RESOLUTIONS = (
(640, 480),
(800, 600),
(1024, 768),
)
In serializers.py:
...
from drf_imgproxy.serializers import ImgproxyResizeableImageField
...
class AngelActivity(ModelSerializer):
...
captured_photo_thumbs = ImgproxyResizeableImageField(
read_only=True,
source='captured_photo'
)
...
See also
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for drf_imgproxy-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27aab9b9b33196372ca3dfb74dbc5c9358a7266afe602a9eae15662534fd71d7 |
|
MD5 | 3cf61db4a51339df67fbd02dce474f0a |
|
BLAKE2b-256 | 861b4d629e402f3f2d2ebb41ffd19026d264502b1e356ea9425f6a35dc734a11 |