Skip to content

MkImageCompare

Show source on GitHub

Node to show an Image comparison (using a slider).

Example: Regular

Jinja

{{ "https://picsum.photos/700" | MkImageCompare(after_image="https://picsum.photos/701") }}

Python

MkImageCompare('https://picsum.photos/700', 'https://picsum.photos/701')

<img-comparison-slider>
  <img src="https://picsum.photos/700" slot="first">
  <img src="https://picsum.photos/701" slot="second">
</img-comparison-slider>
<p><img-comparison-slider>
  <img src="https://picsum.photos/700" slot="first">
  <img src="https://picsum.photos/701" slot="second">
</img-comparison-slider></p>

Bases: MkTemplate

__init__

__init__(before_image: str, after_image: str, **kwargs: Any)

Parameters:

Name Type Description Default
before_image str

Image shown with slider to the right

required
after_image str

Image shown with slider to the left

required
kwargs Any

Keyword arguments passed to parent

{}
graph TD
  93860742946240["mkimagecompare.MkImageCompare"]
  93860738888176["mktemplate.MkTemplate"]
  93860744077920["mkcontainer.MkContainer"]
  93860744073616["mknode.MkNode"]
  93860744080896["node.Node"]
  140589822947552["builtins.object"]
  93860738888176 --> 93860742946240
  93860744077920 --> 93860738888176
  93860744073616 --> 93860744077920
  93860744080896 --> 93860744073616
  140589822947552 --> 93860744080896
/home/runner/work/mknodes/mknodes/mknodes/basenodes/mkimagecompare/metadata.toml
[metadata]
icon = "mdi:image-off"
name = "MkImageCompare"
group = "image"

[[resources.js]]
link = "https://unpkg.com/img-comparison-slider@7/dist/index.js"
defer = true

[[resources.css]]
filename = "https://unpkg.com/img-comparison-slider@7/dist/styles.css"


[examples.regular]
title = "Regular"
jinja = """
{{ "https://picsum.photos/700" | MkImageCompare(after_image="https://picsum.photos/701") }}
"""

[output.html]
template = """
<img-comparison-slider>
  <img src="{{ node.before_image }}" slot="first">
  <img src="{{ node.after_image }}" slot="second">
</img-comparison-slider>
"""
mknodes.basenodes.mkimagecompare.MkImageCompare
class MkImageCompare(mktemplate.MkTemplate):
    """Node to show an Image comparison (using a slider)."""

    ICON = "material/image-off"
    JS_FILES = [resources.JSFile(JS_URL, defer=True)]
    CSS = [resources.CSSFile(CSS_URL)]

    def __init__(
        self,
        before_image: str,
        after_image: str,
        **kwargs: Any,
    ):
        """Constructor.

        Args:
            before_image: Image shown with slider to the right
            after_image: Image shown with slider to the left
            kwargs: Keyword arguments passed to parent
        """
        super().__init__("output/html/template", **kwargs)
        self.before_image = before_image
        self.after_image = after_image