MkBinaryImage
:fa-brands-github: Show source on GitHub
Image carrying the data by itself.¶
Description
This node basically is a regular image link, but carries the image data by itself. The data will get written to the "virtual" folder at the end of the process. It can hold either str or bytes as data.
Example: From data¶
Jinja
{% set svg = '<svg width="90pt" height="90pt" version="1.1" viewBox="0 0 15.875 10.583" xmlns="http://www.w3.org/2000/svg">
<g fill="none" stroke="#F00" stroke-width=".3">
<path d="m6.1295 3.6601 3.2632 3.2632z"/>
<path d="m9.3927 3.6601-3.2632 3.2632z"/>
</g>
</svg>' %}
{{ svg | MkBinaryImage(path="some_image.svg", caption="A simple cross") }}
Python
MkBinaryImage(
'<svg width="90pt" height="90pt" version="1.1" viewBox="0 0 15.875 10.583" xmlns="http://www.w3.org/2000/svg">\n <g fill="none" stroke="#F00" stroke-width=".3">\n <path d="m6.1295 3.6601 3.2632 3.2632z"/>\n <path d="m9.3927 3.6601-3.2632 3.2632z"/>\n </g>\n </svg>',
"some_image.svg",
caption="A simple cross",
)
Example: From icon¶
Python
MkBinaryImage(
'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M13 9h5.5L13 3.5zM6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m0 18h12v-8l-4 4l-2-2zM8 9a2 2 0 0 0-2 2a2 2 0 0 0 2 2a2 2 0 0 0 2-2a2 2 0 0 0-2-2"/></svg>',
"file_image.svg",
width=200,
)
Bases: MkImage
__init__
¶
__init__(
data: bytes | str,
path: str,
*,
target: LinkableType | None = None,
caption: str = "",
title: str = "",
align: Literal["left", "right"] | None = None,
width: int | None = None,
**kwargs: Any
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes | str
|
Image data |
required |
path
|
str
|
path for the image (including extension) |
required |
target
|
LinkableType | None
|
Optional URL or node the image should link to |
None
|
caption
|
str
|
Image caption |
''
|
title
|
str
|
Image title |
''
|
align
|
Literal['left', 'right'] | None
|
Image alignment |
None
|
width
|
int | None
|
Image width in pixels |
None
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
for_file
classmethod
¶
for_file(
path: str | PathLike[str],
storage_options: dict[str, Any] | None = None,
**kwargs: Any
) -> Self
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Path to an image (also takes fsspec protocol URLs) |
required |
storage_options
|
dict[str, Any] | None
|
Options for fsspec backend |
None
|
kwargs
|
Any
|
Keyword arguments passed to constructor |
{}
|
for_icon
classmethod
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
icon
|
str
|
Icon to get a MkBinaryImage for (example: material/file-image) |
required |
kwargs
|
Any
|
Keyword arguments passed to constructor |
{}
|
| Name | Children | Inherits |
|---|---|---|
| MkImage mknodes.basenodes.mkimage Image including optional caption. |
graph TD
1150703457["mkbinaryimage.MkBinaryImage"]
4050704754["mkimage.MkImage"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
4050704754 --> 1150703457
1359323199 --> 4050704754
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkbinaryimage/metadata.toml
[metadata]
icon = "mdi:file-image"
name = "MkBinaryImage"
group = "image"
[examples.from_data]
title = "From data"
jinja = """
{% set svg = '<svg width="90pt" height="90pt" version="1.1" viewBox="0 0 15.875 10.583" xmlns="http://www.w3.org/2000/svg">
<g fill="none" stroke="#F00" stroke-width=".3">
<path d="m6.1295 3.6601 3.2632 3.2632z"/>
<path d="m9.3927 3.6601-3.2632 3.2632z"/>
</g>
</svg>' %}
{{ svg | MkBinaryImage(path="some_image.svg", caption="A simple cross") }}
"""
[examples.from_icon]
title = "From icon"
jinja = """
{{ mk.MkBinaryImage.for_icon("file-image", width=200) }}
"""
Page info
Code for this page
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x785e0f644250>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])