A filter to print the input image in different predefined image sizes.
Project description
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
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lektor-image-filter-1.1.tar.gz.
File metadata
- Download URL: lektor-image-filter-1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03689dcefc6ddcd248da75ea468bdf8f88a1f536a8d9aa7925bf28f89d52c0b1
|
|
| MD5 |
1e9c46319aa5ebabf1d302fe46fbedf0
|
|
| BLAKE2b-256 |
de48e072651b3f270a0a14df0257e65902754dc48ee856f817327a30e44eda84
|
File details
Details for the file lektor_image_filter-1.1-py3-none-any.whl.
File metadata
- Download URL: lektor_image_filter-1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb8a451300d5782a98db806830900b2a3e310afebc01e37ae26a88de99544ab4
|
|
| MD5 |
b7914c6c0d554a45bdb8f0a462c43448
|
|
| BLAKE2b-256 |
d509e708fb40872dc8bc7c63d3b2111e8d69c45f9980fb00a2cc8644825e9b62
|