Wagtail in the News Room - Sævar Öfjörð Magnússon & Arnar Tumi Þorsteinsson
Published June 30, 2022
This video features Arnar Tumi Þorsteinsson at Wagtail Space NL 2022 in Arnhem, Netherlands.
Django’s image filter system can register custom operations through the `register_image_operations` hook in `hooks.py`. Each operation receives a Pillow image and returns a transformed Pillow image, and filters can be chained from the image tag—for example, converting an image to grayscale, then flipping or mirroring it. More practical uses include watermarks, color multiplication, and masking with a grayscale watercolor image; the speaker also showed parameterizing a filter with a hexadecimal color and mentioned ongoing documentation and work to reduce the required boilerplate.
Summarised automatically from the transcript.
Automatically transcribed, so expect mistakes in names and technical terms.
So basically I was just gonna uh because there has been quite a lot of discussion about these image filters uh this week. Um so I just want to show you a little bit about well, basically what's possible. Um when we were doing this uh we found this well basically undocumented hook called register image operations where you can register uh filter operations uh in your Loctile hooks pie. And every one of those is basically a uh pillow um image so it's uh it's a it's a willow
operation where you uh where you have a function that takes in a pillow image and basically returns another pillow image after you've done something with it. Then you have this filter operation with a construct and a run that's basically runs this function. Um so I had a little fun and made a couple of filters Just so I could show you how this works. So we have like grayscale and we have flip and mirror and a couple of things. And all you have to do is basically use the current image tag and you can then just add stuff to the back of it.
So here we have an image basically Yeah, just a normal image of some landscape. And we want a grayscale version. So then you can just add grayscale here and you have a grayscale version. And you can uh because of how these work you can just day chain them so you can just add more if you want. So you want to take You know a grayscale one that's flipped and mirrored. Then you have something that's mil I mean many of these filters are not really usable.
I mean they don't make sense in most use cases, but there are cases where you can use them and It's things like watermarks. It's things like uh like multiply, for us at least. Uh so for for this kind I I want to try to um like add variables so you can actually just do multiply and then add any hex variable that you want so multiply this with a gray color. Then you get like a grayish background thing. If you wanna go crazy, you can go with completely red And you can so you can just play around with this. Um and just
to kinda um end this, uh I did try to do a little bit of masking as well. So I have a image that is basically a grayscale image of a watercolor. mask so you can then you can just add watercolor and then you'll get something that's completely different just by masking out out things like this. Kuhn was doing some documentation on this. So hopefully we'll have some documentation on this register. image filter and uh uh and there was also some work done on uh creating a hook that kind of bypasses all this all this boilerplate
So yeah, hopefully someone can use some of this.
Image filter operations take a Pillow image, transform it, and return another Pillow image. They can be registered through the `register_image_operations` hook in `lektor.plugins.py`, using a filter operation with `construct` and `run` methods.
Discussed at 0:03Use the image tag and append the filter name, such as `grayscale`. Filters can be chained, so an image can be made grayscale, flipped, and mirrored in sequence.
Discussed at 1:34A filter such as `multiply` can accept a hexadecimal color value, letting you multiply the image by gray, red, or another chosen color to create tinted or background-like effects.
Discussed at 2:20A grayscale watercolor image can be used as a mask: applying a `watercolor` filter masks parts of the original image and produces a substantially different result.
Discussed at 3:06Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.
Published June 27, 2024
Published June 27, 2024
Published June 27, 2024
Published June 27, 2024
Published June 27, 2024
Published June 27, 2024