Image
Basic Image
Inherits: LayoutControl
Properties
-
anti_alias(bool) –Whether to paint the image with anti-aliasing.
-
border_radius(BorderRadiusValue | None) –Clips this image to have rounded corners.
-
cache_height(int | None) –The size at which this image should be decoded.
-
cache_width(int | None) –The size at which this image should be decoded.
-
color(ColorValue | None) –If set, this color is blended with each
-
color_blend_mode(BlendMode | None) –Used to combine
colorwith the image. -
error_content(Control | None) –Fallback control to display if the image cannot be loaded
-
exclude_from_semantics(bool) –Whether to exclude this image from semantics.
-
fade_in_curve(AnimationCurve | None) –Animation curve used for the fade-in transition.
-
fade_in_duration(DurationValue | None) –Duration of the fade-in animation when the image loads.
-
fade_out_curve(AnimationCurve | None) –Animation curve used for the fade-out transition.
-
fade_out_duration(DurationValue | None) –Duration of the fade-out animation for the placeholder.
-
filter_quality(FilterQuality) –The rendering quality of the image.
-
fit(BoxFit | None) –Defines how to inscribe this image into the space allocated during layout.
-
gapless_playback(bool) –Whether to continue showing the old image (
True), or briefly show nothing -
placeholder_fit(BoxFit | None) –How to inscribe the placeholder into its space.
-
placeholder_src(str | bytes | None) –A placeholder displayed while the image is loading.
-
repeat(ImageRepeat) –How to paint any portions of the layout bounds not covered by this image.
-
semantics_label(str | None) –A semantic description of this image.
-
src(str | bytes) –The image source.
Examples#
Image gallery#
import flet as ft
def main(page: ft.Page):
page.title = "Image Example"
page.theme_mode = ft.ThemeMode.LIGHT
page.padding = 50
page.add(
ft.Image(
src="app_icon_512.png",
width=100,
height=100,
fit=ft.BoxFit.CONTAIN,
),
gallery := ft.Row(expand=1, wrap=False, scroll=ft.ScrollMode.ALWAYS),
)
for i in range(0, 30):
gallery.controls.append(
ft.Image(
src=f"https://picsum.photos/200/200?{i}",
width=200,
height=200,
fit=ft.BoxFit.NONE,
repeat=ft.ImageRepeat.NO_REPEAT,
border_radius=ft.BorderRadius.all(10),
)
)
page.update()
ft.run(main)
Fade-in images with a placeholder#
import flet as ft
def main(page: ft.Page):
page.add(
ft.Image(
src="https://picsum.photos/320/200?random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8c6QczOjgIwby2nceXKJc36RfcnRybKLr3BmJt/OFM7itnRjOqgTAxSq8ZfVhvKHz0P7PSWunIjwpKgYiADbI/xKDUbka7hGI0+8CCllDshn4m+aA4XRXIhVV8ym+vMaG9zn4AEXliZeYetTcAAAAASUVORK5CYII=", # noqa: E501
fade_in_duration=400,
fade_out_duration=200,
),
)
if __name__ == "__main__":
ft.run(main)
Displaying images from base64 strings and byte data#
import base64
import flet as ft
def main(page: ft.Page):
# image as base64 string
base64_src = "iVBORw0KGgoAAAANSUhEUgAAABkAAAAgCAYAAADnnNMGAAAACXBIWXMAAAORAAADkQFnq8zdAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAA6dJREFUSImllltoHFUYx3/fzOzm0lt23ZrQ1AQbtBehNpvQohgkBYVo410RwQctNE3Sh0IfiiBoIAjqi6TYrKnFy4O3oiiRavDJFi3mXomIBmOxNZe63ay52GR3Zj4f2sTEzmx3m//TYf7/c35zvgPnO6KqrESXqpq3muocAikv6m+/zytj3ejik1VN21G31YA9CgJ6xC+bMyQZPVCuarciPAMYC99V6Vw5pLbFSibHmlVoRVj9P3cmPBM8tSJI/M6mzabpfoAQ9fIF7WK4bd5vvuFnLGgy2vi0abg94A0AcJGvMq3hDxGRyar9r4F+iLAm0yIiRk8m37tctS1WsrIhhrI30+Srmg+J87OXUf3lWGS1q89dC6ltsSanxk4Aj2QBABii96300g87P/rtlrWr8l+vyDMfdlXSyyEikqxsiOUAQJCBhfHdXRfCq1LSsSlcWG+KBAGStvvrMkgiuv8lUc2mREukPwLUfHG+uTQv8Eown7VL3XlbBxYhf1c17hbVF3MDwA9bts280TnaU1YYqPby07aeFlUlHt27wSQ4CLo+F8AvoTCvHmyKF+ZbEb/M77P2LgvAwmrTHAHflN3KZxVbMC2jMFNOpgPnrMSOhvvFkMezXdwV4ePbtvHtxnJAMQ0j4JtVnO+eLb5oiSlt5HDbv7t1O90lpYCCCKbhfzW5kAIwUAazR0BlfII8Ow0I6uoVmI9MyAMwbMs8CExmDbk4zgu931MyO4OI4KrYflkRjOoTI+uM9d1vjotwKPu9QMk/sxzuO8POiVFcdZ1M2YBVsMEAKOqLvaPIe7mACuw0z/80SMH58SMplxlfiDhVi7dw2pltRhjKBQTQdrSja2KKTfE551NHuaZ0QVPvWYQUn31/Vm2nDvgjF4grVJx6suSvrvrSJ/6cSW2Oz9mf264uNrB806xZ1k/CZ49dUKgDEtlCROX2hfHpx8pGuuo3PpqYulw8fjndOp1yhgtNKRevJ1FyR2Ola+jXAjdnwTkZ6o896GdWdxDw7IxFg+0DpmXchTKSBWQnIuJn9u4j7dt+13UfHXEkXQOcuQ4kMhVtqsgUyPiQiPQfHw1NB2sRjmXKuTg1NwwBYLhtPtQX26eqTwGXPDOqvmcC4Hnwfrrad94GrVsOYTqUTkQY+iTlNe/6O1miSP/x0VB/+wMIDwHn/vtV1iQC4Xv95uUEWVCoL9Y5Z+gdovoyMHUFJHv88jmVy0vTuw7cZNv2YaA61Bfb7ZX5F8SaUv2xwZevAAAAAElFTkSuQmCC"
# image as bytes
bytes_src = base64.b64decode(base64_src)
page.add(
ft.Image(
src=base64_src,
width=100,
height=100,
),
ft.Image(
src=bytes_src,
width=100,
height=100,
),
)
ft.run(main)
Displaying a static SVG image#
import flet as ft
def main(page: ft.Page):
svg_image = """
<svg version="1.1" id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px"
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<g>
<path d="M14.43339,18.88085c2.15923,0,3.91203-1.7476,3.91203-3.91226
c0-2.15805-1.7528-3.90566-3.91723-3.90566
c-0.74107,0-1.43221,0.21538-2.02332,0.57576c0.18598-0.05526,0.37562-0.09493,0.58084-0.09493
c1.09756,0,1.98365,0.88609,1.98365,1.98235c0,1.09248-0.88608,1.98376-1.98365,1.98376
c-1.09627,0-1.98235-0.88608-1.98235-1.98376c0-0.20499,0.03979-0.39486,0.09493-0.58096
c-0.36027,0.59135-0.57576,1.28236-0.57576,2.02344C10.52254,17.13325,12.27026,18.88085,14.43339,18.88085z"/>
<path d="M24.55235,1.00006H5.44812C2.99534,1.00006,
1,2.99563,1,5.44747v19.10459c0,2.45278,1.99533,4.44788,4.44812,4.44788
h19.10423c2.45243,0,4.44765-1.9951,4.44765-4.44788V5.44747C29,2.99563,27.00479,1.00006,24.55235,1.00006z
M27.32951,24.55206
c0,1.53175-1.246,2.77774-2.77715,2.77774H5.44812c-1.53151,0-2.77751-1.246-2.77751-2.77774v-8.83719h4.08065
c0.37644,3.90943,3.67563,6.97482,7.67705,6.97482c4.00709,0,7.3065-3.06539,7.68295-6.97482h5.21824V24.55206z
M8.36366,14.96859
c0-3.34831,2.7161-6.06418,6.06453-6.06418c3.35469,0,6.07079,2.71587,6.07079,6.06418c0,3.35492-2.7161,6.07079-6.07079,6.07079
C11.07977,21.03938,8.36366,18.32351,8.36366,14.96859z
M27.32951,13.75472h-5.28579
c-0.58568-3.67705-3.77116-6.5006-7.61541-6.5006c-3.83882,0-7.02383,2.82356-7.60951,6.5006H2.67061V5.44747
c0-1.53128,1.246-2.7768,2.77751-2.7768h19.10423c1.53116,0,2.77715,1.24552,2.77715,2.7768V13.75472z"/>
<path d="M24.06196,5.11637h-1.75185c-0.48236,0-0.87593,0.39345-0.87593,
0.87569v1.75186
c0,0.48225,0.39356,0.87616,0.87593,0.87616h1.75186c0.47776,0,0.87038-0.39392,0.87038-0.87616V5.99205
C24.93234,5.50982,24.53972,5.11637,24.06196,5.11637z"/>
</g>
</svg>"""
page.add(
ft.Image(
src="https://raw.githubusercontent.com/dnfield/flutter_svg/master/packages/flutter_svg/example/assets/wikimedia/Firefox_Logo_2017.svg",
width=200,
height=200,
),
ft.Image(src=svg_image, width=100, height=100, color=ft.Colors.RED),
ft.Image(src=svg_image, width=100, height=100, color=ft.Colors.BLUE),
ft.Container(
bgcolor=ft.Colors.BLACK_87,
border_radius=5,
content=ft.Image(
src=svg_image,
width=100,
height=100,
color=ft.Colors.WHITE,
),
),
)
ft.run(main)
Displaying a dynamic SVG image#
import asyncio
import flet as ft
async def main(page: ft.Page):
svg_image = """
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
<g>
<ellipse ry="{}" rx="{}" id="svg_1" cy="200" cx="200" stroke="#000" fill="#fff"/>
</g>
</svg>
"""
img = ft.Image(src=svg_image.format(0, 0))
page.add(img)
for c in range(0, 10):
for i in range(0, 10):
img.src = svg_image.format(i * 10, i * 10)
img.update()
await asyncio.sleep(0.1)
ft.run(main)
Displaying a Lucide icon#
import flet as ft
"""
- Browse Lucide icons: https://lucide.dev/
- Copy SVG and use it as value for `Image.src`
"""
def main(page: ft.Page):
page.add(
ft.Image(
src='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5"></path><path d="M16 2v4"></path><path d="M8 2v4"></path><path d="M3 10h5"></path><path d="M17.5 17.5 16 16.25V14"></path><path d="M22 16a6 6 0 1 1-12 0 6 6 0 0 1 12 0Z"></path></svg>',
color=ft.Colors.PINK,
),
ft.Image(
src='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>',
color=ft.Colors.GREEN,
),
)
ft.run(main)
Properties#
anti_alias
class-attribute
instance-attribute
#
anti_alias: bool = False
Whether to paint the image with anti-aliasing.
Anti-aliasing alleviates the sawtooth artifact when this image is rotated.
border_radius
class-attribute
instance-attribute
#
border_radius: BorderRadiusValue | None = None
Clips this image to have rounded corners.
cache_height
class-attribute
instance-attribute
#
cache_height: int | None = None
The size at which this image should be decoded.
The image will, however, be rendered to the constraints of the layout regardless of this parameter.
cache_width
class-attribute
instance-attribute
#
cache_width: int | None = None
The size at which this image should be decoded.
The image will, however, be rendered to the constraints of the layout regardless of this parameter.
color
class-attribute
instance-attribute
#
color: ColorValue | None = None
If set, this color is blended with each
image pixel using color_blend_mode.
color_blend_mode
class-attribute
instance-attribute
#
color_blend_mode: BlendMode | None = None
Used to combine color with the image.
In terms of the blend mode, color is the source and this image is the destination.
error_content
class-attribute
instance-attribute
#
error_content: Control | None = None
Fallback control to display if the image cannot be loaded from the provided source.
exclude_from_semantics
class-attribute
instance-attribute
#
exclude_from_semantics: bool = False
Whether to exclude this image from semantics.
fade_in_curve
class-attribute
instance-attribute
#
fade_in_curve: AnimationCurve | None = None
Animation curve used for the fade-in transition.
Defaults to AnimationCurve.EASE_IN_OUT when a fade is enabled.
fade_in_duration
class-attribute
instance-attribute
#
fade_in_duration: DurationValue | None = None
Duration of the fade-in animation when the image loads.
Defaults to 250 milliseconds when any fade option is set.
fade_out_curve
class-attribute
instance-attribute
#
fade_out_curve: AnimationCurve | None = None
Animation curve used for the fade-out transition.
Defaults to AnimationCurve.EASE_OUT when a fade is enabled.
fade_out_duration
class-attribute
instance-attribute
#
fade_out_duration: DurationValue | None = None
Duration of the fade-out animation for the placeholder.
Defaults to 150 milliseconds when any fade option is set.
filter_quality
class-attribute
instance-attribute
#
filter_quality: FilterQuality = MEDIUM
The rendering quality of the image.
fit
class-attribute
instance-attribute
#
fit: BoxFit | None = None
Defines how to inscribe this image into the space allocated during layout.
gapless_playback
class-attribute
instance-attribute
#
gapless_playback: bool = False
Whether to continue showing the old image (True), or briefly show nothing
(False), when the image provider changes.
Has no effect on svg images.
placeholder_fit
class-attribute
instance-attribute
#
placeholder_fit: BoxFit | None = None
How to inscribe the placeholder into its space.
Falls back to fit when omitted.
placeholder_src
class-attribute
instance-attribute
#
A placeholder displayed while the image is loading.
It can be one of the following: - A URL or local asset file path; - A base64 string; - Raw bytes.
Note
SVG sources are currently not supported as placeholders. If provided,
this property will be ignored and the src will be
displayed directly instead.
repeat
class-attribute
instance-attribute
#
repeat: ImageRepeat = NO_REPEAT
How to paint any portions of the layout bounds not covered by this image.
semantics_label
class-attribute
instance-attribute
#
semantics_label: str | None = None
A semantic description of this image.
Used to provide a description of the image to TalkBack on Android, and VoiceOver on iOS.
src
instance-attribute
#
The image source.
It can be one of the following: - A URL or local asset file path; - A base64 string; - Raw bytes.

