You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: components/animation.rst
+6-9
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ It adds additional lambda methods: ``next_frame()``, ``prev_frame()`` and ``set_
12
12
- file: "animation.gif"
13
13
id: my_animation
14
14
resize: 100x100
15
+
type: RGB565
15
16
16
17
The animation can be rendered just like the image component with the ``image()`` function of the display component.
17
18
@@ -50,18 +51,15 @@ Configuration variables:
50
51
in your display code.
51
52
- **resize** (*Optional*, string): If set, this will resize all the frames to fit inside the given dimensions ``WIDTHxHEIGHT``
52
53
and preserve the aspect ratio.
53
-
- **type** (*Optional*): Specifies how to encode each frame internally. Defaults to ``BINARY``.
54
+
- **type** (**Required**): Specifies how to encode image internally. See the :ref:`image component <display-image>` for more information.
54
55
55
56
- ``BINARY``: Two colors, suitable for 1 color displays or 2 color image in color displays. Uses 1 bit
56
-
per pixel, 8 pixels per byte.
57
-
- ``TRANSPARENT_BINARY``: One color, any pixel that is fully transparent will not be drawn, and any other pixel
58
-
will be the on color. Uses 1 bit per pixel, 8 pixels per byte.
57
+
per pixel, 8 pixels per byte. Only ``chroma_key`` transparency is available.
59
58
- ``GRAYSCALE``: Full scale grey. Uses 8 bits per pixel, 1 pixel per byte.
60
-
- ``RGB565``: Lossy RGB color stored. Uses 2 bytes per pixel.
61
-
- ``RGB24``: Full RGB color stored. Uses 3 bytes per pixel.
62
-
- ``RGBA``: Full RGB color stored. Uses 4 bytes per pixel. Any pixel with an alpha value < 127 will not be drawn.
59
+
- ``RGB565``: Lossy RGB color stored. Uses 2 bytes per pixel, 3 with an alpha channel.
60
+
- ``RGB``: Full RGB color stored. Uses 3 bytes per pixel, 4 with an alpha channel.
63
61
64
-
- **use_transparency** (*Optional*): If set the alpha channel of the input image will be taken into account, and pixels with alpha < 127 will not be drawn. For image types without explicit alpha channel, the color (0, 0, 1) (very dark blue) will be mapped to black, to be able to store transparency information within the image. Explicitly transparent types (``TRANSPARENT_BINARY`` and ``RGBA``) default to ``True`` and cannot be set to ``False``; other types default to ``False``.
62
+
- **use_transparency** (*Optional*): If set the alpha channel of the input image will be taken into account. The possible values are ``opaque`` (default), ``chroma_key`` and ``alpha_channel``. See discussion on transparency in the :ref:`image component <display-image>`.
65
63
- **loop** (*Optional*): If you want to loop over a subset of your animation (e.g. a fire animation where the fire "starts", then "burns" and "dies") you can specify some frames to loop over.
66
64
67
65
- **start_frame** (*Optional*, int): The frame to loop back to when ``end_frame`` is reached. Defaults to the first frame in the animation.
@@ -83,4 +81,3 @@ Actions:
83
81
84
82
- **id** (**Required**, :ref:`config-id`): The ID of the animation to animate.
85
83
- **frame** (**Required**, int): The frame index to show next.
Copy file name to clipboardexpand all lines: components/image.rst
+61-14
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ For showing images downloaded at runtime, take a look at the :ref:`Online Image
15
15
16
16
image:
17
17
- file: "image.png"
18
+
type: binary
18
19
id: my_image
19
20
resize: 100x100
20
21
@@ -23,12 +24,15 @@ For showing images downloaded at runtime, take a look at the :ref:`Online Image
23
24
image:
24
25
- file: mdi:alert-outline
25
26
id: alert
27
+
type: grayscale
28
+
use_transparency: alpha_channel
26
29
resize: 80x80
27
30
28
31
.. code-block:: yaml
29
32
30
33
image:
31
34
- file: https://esphome.io/_images/logo.png
35
+
type: rgb565
32
36
id: esphome_logo
33
37
resize: 200x162
34
38
@@ -46,36 +50,70 @@ Configuration variables:
46
50
in your display code.
47
51
- **resize** (*Optional*, string): If set, this will resize the image to fit inside the given dimensions ``WIDTHxHEIGHT``
48
52
and preserve the aspect ratio.
49
-
- **type** (*Optional*): Specifies how to encode image internally. Defaults to ``BINARY`` for local and remote images and ``TRANSPARENT_BINARY`` for MDIs.
53
+
- **type** (**Required**): Specifies how to encode image internally.
50
54
51
55
- ``BINARY``: Two colors, suitable for 1 color displays or 2 color image in color displays. Uses 1 bit
52
-
per pixel, 8 pixels per byte.
53
-
- ``TRANSPARENT_BINARY``: One color, any pixel that is fully transparent will not be drawn, and any other pixel
54
-
will be the on color. Uses 1 bit per pixel, 8 pixels per byte.
56
+
per pixel, 8 pixels per byte. Only ``chroma_key`` transparency is available.
55
57
- ``GRAYSCALE``: Full scale grey. Uses 8 bits per pixel, 1 pixel per byte.
56
-
- ``RGB565``: Lossy RGB color stored. Uses 2 bytes per pixel.
57
-
- ``RGB24``: Full RGB color stored. Uses 3 bytes per pixel.
58
-
- ``RGBA``: Full RGB color stored. Uses 4 bytes per pixel. Any pixel with an alpha value < 127 will not be drawn.
58
+
- ``RGB565``: Lossy RGB color stored. Uses 2 bytes per pixel, 3 with an alpha channel.
59
+
- ``RGB``: Full RGB color stored. Uses 3 bytes per pixel, 4 with an alpha channel.
59
60
60
-
- **use_transparency** (*Optional*): If set the alpha channel of the input image will be taken into account, and pixels with alpha < 127 will not be drawn. For image types without explicit alpha channel, the color (0, 0, 1) (very dark blue) will be mapped to black, to be able to store transparency information within the image. Explicitly transparent types (``TRANSPARENT_BINARY`` and ``RGBA``) default to ``True`` and cannot be set to ``False``; other types default to ``False``.
61
+
- **use_transparency** (*Optional*): If set the alpha channel of the input image will be taken into account. The possible values are ``opaque`` (default), ``chroma_key`` and ``alpha_channel``. See discussion on transparency below.
61
62
62
63
- **dither** (*Optional*): Specifies which dither method used to process the image, only used in GRAYSCALE and BINARY type image. Defaults to ``NONE``. You can read more about it `here <https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=Dither#PIL.Image.Image.convert>`__ and `here <https://en.wikipedia.org/wiki/Dither>`__.
63
64
64
-
- ``NONE``: Every pixel convert to its nearest color.
65
+
- ``NONE``: Every pixel converts to its nearest color.
65
66
- ``FLOYDSTEINBERG``: Uses Floyd-Steinberg dither to approximate the original image luminosity levels.
66
67
67
68
.. note::
68
69
69
70
To use images you will need to have the python ``pillow`` package installed.
70
71
Additionally, if you want to use SVG images (including MDI images), you will
71
-
additionally need to have the python ``cairosvg`` package installed.
72
+
additionally need to have the python ``cairosvg`` package installed. These are automatically installed when
73
+
setting up ESPHome via the usual methods.
72
74
73
-
If you're running this as a Home Assistant add-on or with the official ESPHome docker image, it should already be installed.
75
+
Grouping images by type
76
+
-----------------------
74
77
75
-
Use ``pip install "esphome[displays]"`` to install these optional dependencies with
76
-
the versions that ESPHome requires.
78
+
You can group images by type to make it easier to manage them. This is useful when you have a lot of images to be encoded in the same way, and avoids having to repeat the same type for each image. The type name is used as the key for the group. For example:
77
79
78
-
And then later in code:
80
+
.. code-block:: yaml
81
+
82
+
image:
83
+
grayscale:
84
+
- file: "image1.png"
85
+
id: image1
86
+
- file: "image2.png"
87
+
id: image2
88
+
- file: "image3.png"
89
+
id: image3
90
+
91
+
rgb565:
92
+
- file: "image4.png"
93
+
id: image4
94
+
- file: "image5.png"
95
+
id: image5
96
+
97
+
In addition, the default transparency type can be set within a type group by using the transparency type as a key.
98
+
99
+
.. code-block:: yaml
100
+
101
+
image:
102
+
rgb565:
103
+
alpha_channel:
104
+
- file: "image1.png"
105
+
id: image1
106
+
- file: "image2.png"
107
+
id: image2
108
+
opaque:
109
+
- file: "image2.png"
110
+
111
+
Displaying Images
112
+
-----------------
113
+
114
+
Images may be used in LVGL configurations wherever an image is required. See the :doc:`LVGL </components/lvgl/index>` documentation for more information.
115
+
116
+
To display an image directly on an ESPHome display, you can use the ``image`` method in the display lambda.
79
117
80
118
.. code-block:: yaml
81
119
@@ -123,3 +161,12 @@ be supplied to modify the color used to represent the on and off bits respective
123
161
124
162
You can also use this to invert images in two color displays, use ``COLOR_OFF`` then ``COLOR_ON``
125
163
as the additional parameters.
164
+
165
+
Transparency options
166
+
--------------------
167
+
168
+
By default transparency is not used. If ``use_transparency: chroma_key`` is set then a specific colour (0, 1, 0) will be used to replace any transparent or partially transparent portions of the image. This will not be drawn when rendering the image, allowing the background to be visible.
169
+
170
+
If ``use_transparency: alpha_channel`` is set, then each pixel of the image will be assigned an additional byte with a transparency value. This is useful mainly when using :doc:`LVGL </components/lvgl/index>` as the ``alpha_channel`` transparency will enable smooth blending of transparent images with the background.
171
+
When using the display lambda image drawing functions these will draw or not draw the pixel, no blending with the background will be done.
172
+
The ``BINARY`` format only permits ``chroma_key`` transparency, which effectively turns the image into an alpha mask with one bit per pixel. GRAYSCALE images with transparency store the alpha channel only, and remain 1 byte per pixel.
Copy file name to clipboardexpand all lines: components/lvgl/widgets.rst
+1-1
Original file line number
Diff line number
Diff line change
@@ -804,7 +804,7 @@ Images are the basic widgets used to display images.
804
804
805
805
.. note::
806
806
807
-
Currently ``RGB565`` type images are supported, with transparency using the optional parameter ``use_transparency`` set to ``true``. See :ref:`display-image` for how to load an image for rendering in ESPHome.
807
+
Currently ``RGB565`` type images are supported, with transparency using the optional parameter ``use_transparency`` set. See :ref:`display-image` for how to load an image for rendering in ESPHome.
0 commit comments