Image Widget
This content is for v1.1.1. Switch to the latest version for up-to-date documentation.
Image renders raster graphics on screen with native hardware decoding. It supports packaged project assets, images in assets/, data URIs, and asynchronous remote HTTPS URLs (new in 1.1.0).
Code Example
Section titled “Code Example”from zkite import Column, Image, Text
def MediaCards(): return Column( "items-center p-4 bg-slate-900 rounded-2xl gap-3", # 1. Local packaged asset from recursive assets/ folder Image( "w-24 h-24 rounded-full border-2 border-emerald-500", src="assets/images/avatar.png", alt="User Profile Photo", fit="cover" ), # 2. Asynchronous remote HTTPS URL (new in 1.1.0) Image( "w-full h-48 rounded-xl", src="https://images.example.com/banners/hero.jpg", alt="Hero Banner", fit="cover" ), Text("text-lg font-bold text-white", "Alex Morgan"), )Constructor & Properties
Section titled “Constructor & Properties”Image( classes: str, src: str, alt: str = "", fit: str = "cover", key: str | None = None)| Parameter | Type | Default | Description |
|---|---|---|---|
classes |
str |
None | Utility classes defining explicit width, height (w-24 h-24), border radius, and clips. |
src |
str |
None | Asset path (assets/photo.png, icon.png), data URI, or HTTPS URL (https://...). |
alt |
str |
"" |
Accessibility text description for screen readers. |
fit |
str |
"cover" |
Scaling mode: "cover", "contain", "fill", "none", or "scale-down". |
key |
str |
None |
Stable widget key across tree re-renders. |
Remote HTTPS Image Loading (New in 1.1.0)
Section titled “Remote HTTPS Image Loading (New in 1.1.0)”ZKite 1.1.0 includes a native asynchronous HTTPS image loader:
- Formats: PNG and JPEG-family formats over HTTPS with verified TLS certificates.
- Network & Workers: Uses 4 background worker threads and a 15-second network timeout.
- Limits: 2 MiB maximum size per image.
- Caching & Retries: Images are cached in a bounded memory cache. If a download fails, an empty placeholder is shown with a diagnostic in device logs; a subsequent render can retry after 30 seconds.
- Security: HTTPS redirects cannot downgrade to unencrypted HTTP.
- Permission: Requires
"permissions": ["INTERNET"]underandroidinapp.json.
Packaged Local Assets (assets/)
Section titled “Packaged Local Assets (assets/)”- Recursive Staging: The entire
assets/directory is packaged recursively. Use project-relative paths like"assets/images/logo.png". - Top-Level Files: PNG/JPG/JPEG files directly beside
main.pyare also staged (retained from 1.0.0 for backwards compatibility). - Always Provide Layout Sizing: Always assign an explicit width and height (
w-24 h-24,w-full h-48) in the class string. Without layout constraints, the widget may collapse to zero height.
App Launcher Icon
Section titled “App Launcher Icon”The launcher icon is configured separately in app.json:
{ "android": { "icon": "assets/icon.png" }}- Use a real square PNG (recommended 192x192 pixels or larger).
- After changing the icon, rerun
zkite runor restartzkite devso the APK resource is re-packaged.
