Skip to content

Commit 0358053

Browse files
authored
Update AVIF documentation (#207)
1 parent 2eb0059 commit 0358053

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

README.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
Responsive cross-browser image library using modern codes like AVIF & WebP.
66

7-
* responsive web images using the [picture](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) tag
8-
* native grid system support
9-
* serve files with or without a CDN
10-
* placeholders for local development
11-
* migration support
12-
* async image processing for [Celery], [Dramatiq] or [Django RQ][django-rq]
13-
* [DRF] support
7+
- responsive web images using the [picture](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) tag
8+
- native grid system support
9+
- serve files with or without a CDN
10+
- placeholders for local development
11+
- migration support
12+
- async image processing for [Celery], [Dramatiq] or [Django RQ][django-rq]
13+
- [DRF] support
1414

1515
[![PyPi Version](https://img.shields.io/pypi/v/django-pictures.svg)](https://pypi.python.org/pypi/django-pictures/)
1616
[![Test Coverage](https://codecov.io/gh/codingjoe/django-pictures/branch/main/graph/badge.svg)](https://codecov.io/gh/codingjoe/django-pictures)
@@ -21,8 +21,9 @@ Responsive cross-browser image library using modern codes like AVIF & WebP.
2121
Before you start, it can be a good idea to understand the fundamentals of
2222
[responsive images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
2323

24-
Once you get a feeling how complicated things can get with all device types, you'll probably find
25-
a new appreciation for this package and are ready to adopt in you project :)
24+
Once you get a feeling how complicated things can get with all device types,
25+
you'll probably find a new appreciation for this package,
26+
and are ready to adopt in your project :)
2627

2728
```python
2829
# models.py
@@ -41,12 +42,13 @@ class Profile(models.Model):
4142
```
4243

4344
The keyword arguments `m=6 l=4` define the columns the image should take up in
44-
a grid at a given breakpoint. So in this example, the image will take up
45-
6 columns on medium screens and 4 columns on large screens. You can define your
46-
grid and breakpoints as you want, refer to the [grid columns](#grid-columns) and
45+
a grid at a given breakpoint. So in this example, the image will take up
46+
six columns on medium screens and four columns on large screens. You can define
47+
your grid and breakpoints as you want, refer to the [grid columns](#grid-columns) and
4748
[breakpoints](#breakpoints) sections.
4849

4950
The template above will render into:
51+
5052
```html
5153
<picture class="my-picture">
5254
<source type="image/webp"
@@ -128,19 +130,14 @@ Although the `picture`-tag is [adequate for most use-cases][caniuse-picture],
128130
some remain, where a single `img` tag is necessary. Notably in email, where
129131
[most clients do support WebP][caniemail-webp] but not [srcset][caniemail-srcset].
130132
The template tag `img_url` returns a single size image URL.
131-
In addition to the ratio you will need to define the `file_type`
133+
In addition to the ratio, you will need to define the `file_type`
132134
as well as the `width` (absolute width in pixels).
133135

134-
135136
```html
136137
{% load pictures %}
137-
<img src="{% img_url profile.picture ratio="3/2" file_type="webp" width=800 %}" alt="profile picture">
138+
<img src="{% img_url profile.picture ratio='3/2' file_type='webp' width=800 %}" alt="profile picture">
138139
```
139140

140-
[caniuse-picture]: https://caniuse.com/picture
141-
[caniemail-webp]: https://www.caniemail.com/features/image-webp/
142-
[caniemail-srcset]: https://www.caniemail.com/features/html-srcset/
143-
144141
## Config
145142

146143
### Aspect ratios
@@ -172,17 +169,17 @@ class Profile(models.Model):
172169
If you don't specify an aspect ratio or None in your template, the image will be
173170
served with the original aspect ratio of the file.
174171

175-
You may only use aspect ratios in templates, that have been defined on the model.
172+
You may only use aspect ratios in templates that have been defined on the model.
176173
The model `aspect_ratios` will default to `[None]`, if other value is provided.
177174

178175
### Breakpoints
179176

180-
You may define your own breakpoints, they should be identical to the ones used
181-
in your css library. Simply override the `PICTURES["BREAKPOINTS"]` setting.
177+
You may define your own breakpoints they should be identical to the ones used
178+
in your CSS library. This can be achieved by overriding the `PICTURES["BREAKPOINTS"]` setting.
182179

183180
### Grid columns
184181

185-
Grids are so common in web design, that they even made it into CSS.
182+
Grids are so common in web design that they even made it into CSS.
186183
We default to 12 columns, but you can override this setting, via the
187184
`PICTURES["GRID_COLUMNS"]` setting.
188185

@@ -196,13 +193,20 @@ You may also set it to `None`, should you not use a container.
196193

197194
### File types
198195

199-
Unless you still services IE11 clients, you should be fine serving just
200-
[WebP](https://caniuse.com/webp). Sadly, [AVIF](https://caniuse.com/avif)
201-
(WebP's successor) is
202-
[not yet supported by Pillow](https://github.com/python-pillow/Pillow/pull/5201).
196+
[AVIF](https://caniuse.com/avif) ([WebP](https://caniuse.com/webp)'s successor)
197+
is the best and most efficient image format available today. It is part of
198+
Baseline 2024 and is supported by all major browsers. Additionally, most modern
199+
devices will have hardware acceleration for AVIF decoding. This will not only
200+
reduce network IO but speed up page rendering.
201+
202+
> [!NOTE]
203+
> Pillow 11.2.1 shipped without AVIF binaries.
204+
> You will need to [install Pillow from source][libavif-install] for AVIF support.
205+
> This should be resolved in upcoming releases, once
206+
> [#8858](https://github.com/python-pillow/Pillow/pull/8858) has been merged.
203207
204-
If you are serving IE11 use add `JPEG` to the list. Beware though, that this may
205-
drastically increase you storage needs.
208+
Should you still serve IE11, use add `JPEG` to the list. But, beware, this may
209+
drastically increase your storage needs.
206210

207211
### Pixel densities
208212

@@ -224,13 +228,11 @@ processor, should you need to do some custom processing.
224228
## Migrations
225229

226230
Django doesn't support file field migrations, but we do.
227-
You can simply auto create the migration and replace Django's
231+
You can auto create the migration and replace Django's
228232
`AlterField` operation with `AlterPictureField`. That's it.
229233

230234
You can follow [the example][migration] in our test app, to see how it works.
231235

232-
[migration]: tests/testapp/migrations/0002_alter_profile_picture.py
233-
234236
## Contrib
235237

236238
### Django Rest Framework ([DRF])
@@ -257,7 +259,7 @@ class PictureSerializer(serializers.Serializer):
257259
picture = PictureField(aspect_ratios=["16/9"], file_types=["WEBP"])
258260
```
259261

260-
You also may provide optional GET parameters to the serializer,
262+
You also may provide optional GET parameters to the serializer
261263
to specify the aspect ratio and breakpoints you want to include in the response.
262264
The parameters are prefixed with the `fieldname_`
263265
to avoid conflicts with other fields.
@@ -303,7 +305,7 @@ Should you use a CDN, or some other external image processing service, you can
303305
set this up in two simple steps:
304306

305307
1. Override `PICTURES["PROCESSOR"]` to disable the default processing.
306-
2. Override `PICTURES["PICTURE_CLASS"]` implement any custom behavior.
308+
1. Override `PICTURES["PICTURE_CLASS"]` implement any custom behavior.
307309

308310
```python
309311
# settings.py
@@ -317,10 +319,11 @@ The `MyPicture`class should implement the url property, which returns the URL
317319
of the image. You may use the `Picture` class as a base class.
318320

319321
Available attributes are:
320-
* `parent_name` - name of the source file uploaded to the `PictureField`
321-
* `aspect_ratio` - aspect ratio of the output image
322-
* `width` - width of the output image
323-
* `file_type` - file type of the output image
322+
323+
- `parent_name` - name of the source file uploaded to the `PictureField`
324+
- `aspect_ratio` - aspect ratio of the output image
325+
- `width` - width of the output image
326+
- `file_type` - format of the output image
324327

325328
```python
326329
# path/to.py
@@ -337,7 +340,12 @@ class MyPicture(Picture):
337340
)
338341
```
339342

340-
[drf]: https://www.django-rest-framework.org/
343+
[caniemail-srcset]: https://www.caniemail.com/features/html-srcset/
344+
[caniemail-webp]: https://www.caniemail.com/features/image-webp/
345+
[caniuse-picture]: https://caniuse.com/picture
341346
[celery]: https://docs.celeryproject.org/en/stable/
342-
[dramatiq]: https://dramatiq.io/
343347
[django-rq]: https://github.com/rq/django-rq
348+
[dramatiq]: https://dramatiq.io/
349+
[drf]: https://www.django-rest-framework.org/
350+
[libavif-install]: https://pillow.readthedocs.io/en/latest/installation/building-from-source.html#external-libraries
351+
[migration]: tests/testapp/migrations/0002_alter_profile_picture.py

0 commit comments

Comments
 (0)