image-filter
A Lektor filter to print the input image in different predefined image sizes.
This plugin is designed to work together with the lektor-image-resize Plugin.
Current Filters:
imagessrcsetwebpwill print the configured sizes aswebpto put in asrcsetelement.imageswidthwebpwill print the first configuredwebpimage width to put in awidthelement.imagessrcwebpwill print the first configuredwebpimage name to put in asrcelement.imagessrcsetjpgwill print the configured sizes asjpgto put in asrcsetelement.imageswidthjpgwill print the first configuredjpgimage width to put in awidthelement.imagessrcjpgwill print the first configuredjpgimage name to put in asrcelement.
Configuration
You can configure the image width in the config file called configs/image-resize.ini and add
a few sections for images. The section names can be whatever you want, the
final images will be called $(imagename)-$(sectionname).jpg and $(imagename)-$(sectionname).webp.
If the max_width enty does not exist the entry will be ignored.
Here is a example config file:
[small]
max_width = 512
[medium]
max_width = 900
max_height = 900
[woowee]
max_width = 1440
Simple Lektor Example
Lektor Jinja2 Input
<img src="{{ 'waffle.jpg'|imagessrcjpg }}" width="{{ 'waffle.jpg'|imagessrcjpg }}"
srcset="{{ 'waffle.jpg'|imagessrcsetjpg }}" />
Lektor HTML Output:
<img src="waffle-small.webp" width="512"
srcset="waffle-small.webp 512w,
waffle-medium.webp 900w,
waffle-woowee.webp 1440w," />
Advanced Lektor Example
Lektor Models Definition
[fields.my_image]
label = Example Image
description = Select a Image from the Attatchments of this site. Upload one, if no one is available
type = select
source = record.attachments.images
Lektor Jinja2 Input
{% set image = record.attachments.images.get(this.my_image) %}
<img src="{{ image | url | imagessrcwebp }}" width="{{ image | url | imageswidthwebp }}"
srcset="{{ image | url | imagessrcsetwebp }}" />
Explaination Input:
- First we created the Jinaja2-variable
imagethat will contain our image (this.box_image) to make this example better readable. (We assume you know how to create variables in lektor) - Next line we created a html image tag with
srcandwidth - Last we created the
srcsetelement with all configured sizes. - By the way we added the url filter in our example. there are options like
|url(external=true)that you could like.
Lektor HTML Output
<img src="waffle-small.webp" width="512"
srcset="waffle-small.webp 512w,
waffle-medium.webp 900w,
waffle-woowee.webp 1440w," />
(Please note that we added some new lines to make the example better readable ans we assume that my_image: waffle.jpg comes from your .lr file, created via lektor admin menu)
Installation
lektor plugin add lektor-image-filter
Release files for lektor-image-filter 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 | |
|---|---|---|---|
| lektor-image-filter-1.1.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lektor_image_filter-1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / lektor-image-filter-1.1.tar.gz
| Download URL | lektor-image-filter-1.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03689dcefc6ddcd248da75ea468bdf8f88a1f536a8d9aa7925bf28f89d52c0b1
|
|
BLAKE2b-256 checksum How to use checksums |
de48e072651b3f270a0a14df0257e65902754dc48ee856f817327a30e44eda84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / lektor_image_filter-1.1-py3-none-any.whl
| Download URL | lektor_image_filter-1.1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb8a451300d5782a98db806830900b2a3e310afebc01e37ae26a88de99544ab4
|
|
BLAKE2b-256 checksum How to use checksums |
d509e708fb40872dc8bc7c63d3b2111e8d69c45f9980fb00a2cc8644825e9b62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|