Skip to main content

image-filter

PyPI version Downloads Linting Python package Upload Python Package MIT License

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:

  • imagessrcsetwebp will print the configured sizes as webp to put in a srcset element.
  • imageswidthwebp will print the first configured webp image width to put in a width element.
  • imagessrcwebp will print the first configured webp image name to put in a src element.
  • imagessrcsetjpg will print the configured sizes as jpg to put in a srcset element.
  • imageswidthjpg will print the first configured jpg image width to put in a width element.
  • imagessrcjpg will print the first configured jpg image name to put in a src element.

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 image that 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 src and width
  • Last we created the srcset element 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)

Source distribution for lektor-image-filter 1.1
File Size Uploaded
lektor-image-filter-1.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lektor-image-filter 1.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

3.0

2 release files

2.1

2 release files

2.0

2 release files

1.2

2 release files

This release

1.1 This release

2 release files

1.0

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page