## Demo: image ### ImageDemo.svelte ```svelte

Component

A plain <Image> renders a single resized <img> with no client JS:

A resized random photo

With a blur placeholder

Add placeholder to show a ThumbHash blur until the image loads — it's the <img>'s own background-image, so no client JS is needed. The placeholder shows first, then the loaded image that paints over it:

{#if blur}
A resized random photo with blur-up
{:else}
A resized random photo with blur-up
{/if}

Inside a hydrated island

<Image> also works inside a mochi:hydrate island: the server-minted URL and placeholder are serialized into the page (via Svelte's hydratable) and reused during hydration, so the browser never needs the encryption secret. The button is live client-side state:

Caveat: props passed to a hydrated island — like this card's src — are serialized in plain text into the page for hydration, so the source URL is visible to the client here. If your origin must stay secret, keep <Image> in server-rendered markup or a server island, whose props are encrypted.

Programmatic

getResizedImage() returns an encrypted URL you can use anywhere:

{directUrl}
Resized via getResizedImage()

This uses the default fit: 'inside', which preserves aspect ratio and fits within the 400×400 box — so this 3:2 photo becomes 400×267. Pass fit: 'fill' to force an exact square (stretching); Bun.Image has no crop/cover mode.

Full-size original

getImage() returns an encrypted URL for the un-resized original — fetched once and shared, so every resized variant above reuses this one cached download:

{originalUrl}
Full-size original via getImage()

Gallery

Fourteen source photos, each resized to a square <img> on the fly with a placeholder blur-up — all server-rendered, zero client JS:

{#each gallery as src, i (src)} Gallery photo {i + 1} {/each}
``` ### ImageIslandCard.svelte ```svelte
A photo rendered inside a hydrated island
``` ### routes.ts ```ts import { Mochi } from 'mochi-framework'; import type { MochiRouteValue } from 'mochi-framework'; export const routes: Record = { '/demos/image': Mochi.page('./src/demos/image/ImageDemo.svelte'), }; ``` ### index.ts ```ts import { Mochi, logger } from 'mochi-framework'; import { routes } from './routes'; await Mochi.serve({ port: 3333, development: process.env.MODE === 'development', routes, }); logger.info('Server running at http://localhost:3333'); ```