Learn · 09 of 09
Images.
Image accepts three source shapes: named resource paths,
local file URLs, and embedded bytes. The runtime resolves image
metadata before layout, then the host presents the raster attachment
using the best protocol available for that terminal.
Supported input formats are PNG, baseline JPEG, and GIF. When you
pass bytes, the decoder chooses the format from the leading magic
bytes; authors do not need separate PNG/JPEG/GIF view types.
Source choices
-
Image(path:) resolves a named resource against
EnvironmentValues.imageResourceRoots. Prefer it for
app-owned assets.
-
Image(fileURL:) points at a local file URL string.
Prefer it for user-picked or dropped files.
-
Image(data:) embeds bytes directly in the view value.
Prefer it for generated, downloaded-then-cached, or tiny demo
assets.
Sizing modes
Without modifiers, an image reports an intrinsic cell size derived
from its pixel size and the current cell-pixel metrics. Use
.resizable() to stretch into the proposed frame,
.scaledToFit() to preserve aspect while fitting inside
the frame, and .scaledToFill() to preserve aspect while
covering the frame.
.scaledToFill() can overflow the frame by design. Pair
it with .clipped() when you want a cropped thumbnail.
Host presentation
The rasterizer emits an image attachment with source, destination
bounds, visible bounds, pixel size, and scaling mode. The terminal
host can present it through Kitty graphics or Sixel when available;
otherwise it composites a text fallback into the cell buffer. The
authored view does not need to branch on host capability.
What to read after Learn