Skip to content

Image

A widget that displays an image.

Basic Usage

Use NetworkImage or AssetImage to specify the image source.

Network Image:
With Custom Opacity (0.5):
vue
<template>
  <Column :spacing="20" cross-axis-alignment="start">
    <Text>Network Image:</Text>
    <Image :image="NetworkImage('https://picsum.photos/300/200')" width="300" height="200" />

    <Text>With Custom Opacity (0.5):</Text>
    <Image
      :image="NetworkImage('https://picsum.photos/300/200?random=2')"
      width="300"
      height="200"
      :opacity="0.5"
    />
  </Column>
</template>

<script setup lang="ts">
import { Column, Image, NetworkImage, Text } from "fluekit";
</script>

Image Fit

The fit property controls how the image should be inscribed into the box.

fill
contain
cover
none
scaleDown
vue
<template>
  <Wrap :spacing="20" :run-spacing="20">
    <Column v-for="fit in fits" :key="fit" cross-axis-alignment="center">
      <Container
        width="150"
        height="100"
        color="#eee"
        :decoration="BoxDecoration({ border: Border.all({ color: '#ccc' }) })"
      >
        <Image :image="NetworkImage('https://picsum.photos/300/300')" :fit="fit" />
      </Container>
      <Text>{{ fit }}</Text>
    </Column>
  </Wrap>
</template>

<script setup lang="ts">
import { Border, BoxDecoration, Column, Container, Image, NetworkImage, Text, Wrap } from "fluekit";

const fits = ["fill", "contain", "cover", "none", "scaleDown"] as const;
</script>

API

Props

NameTypeDefaultDescription
imageImageProvider-The image provider (e.g., NetworkImage('url')).
widthnumber | string-The width of the image.
heightnumber | string-The height of the image.
fitBoxFit'contain'How to inscribe the image into the space allocated during layout.
alignmentAlignment'center'How to align the image within its bounds.
opacitynumber1.0The opacity of the image.
filterQualityFilterQuality'medium'The rendering quality of the image.
altstring''Semantic description of the image.

Events

NameDescriptionParameters
loadTriggered when the image is successfully loaded.Event
errorTriggered when the image fails to load.Event

ImageProvider

Functions to create image providers:

  • NetworkImage(url, options?): Creates an object that fetches the image at the given URL.
  • AssetImage(name, options?): Creates an object that fetches an image from an asset bundle.
    • If options.package is provided, the path becomes ${package}/${name}.
    • Can be configured globally via setAssetBaseURL.

Asset Management

FlueKit provides helpers to manage asset paths, useful for deploying to CDNs or handling multi-package structures.

setAssetBaseURL(url: string)

Sets the global base URL for all AssetImage calls.

typescript
import { setAssetBaseURL, AssetImage } from "fluekit";

// Set global base path (e.g. in main.ts)
setAssetBaseURL("https://cdn.example.com/assets/");

// Usage
AssetImage("logo.png");
// -> https://cdn.example.com/assets/logo.png

AssetImage("icon.png", { package: "common" });
// -> https://cdn.example.com/assets/common/icon.png

createAssetImage(options: { package: string })

Creates a factory function for a specific package, reducing boilerplate.

typescript
import { createAssetImage } from "fluekit";

// Create a helper for a specific module/package
const CommonAssets = createAssetImage({ package: "common" });

// Usage
const icon = CommonAssets("icons/user.png");
// -> {base_url}/common/icons/user.png