Skip to main content

A filter to print the input image in different predefined image sizes.

Project description

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

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

lektor-image-filter-1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

lektor_image_filter-1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for lektor-image-filter-1.1.tar.gz
Algorithm Hash digest
SHA256 03689dcefc6ddcd248da75ea468bdf8f88a1f536a8d9aa7925bf28f89d52c0b1
MD5 1e9c46319aa5ebabf1d302fe46fbedf0
BLAKE2b-256 de48e072651b3f270a0a14df0257e65902754dc48ee856f817327a30e44eda84

See more details on using hashes here.

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

Hashes for lektor_image_filter-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb8a451300d5782a98db806830900b2a3e310afebc01e37ae26a88de99544ab4
MD5 b7914c6c0d554a45bdb8f0a462c43448
BLAKE2b-256 d509e708fb40872dc8bc7c63d3b2111e8d69c45f9980fb00a2cc8644825e9b62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page