Image
JPEG, PNG, GIF, WebP and SVG images, on their own, in a line of text or behind a box.
Import them from @inkoxide/react, @inkoxide/vue or @inkoxide/svelte; an Angular template writes them as <ink-image>, <ink-image-background>. Examples, and how these components work together, are in the guide.
Image
JPEG, PNG, GIF, WebP or SVG. fit (or objectFit in its style): fill, contain, cover, none; objectPosition in its style places the fitted image.
import { Document, Image, Page, Text } from '@inkoxide/react';
// A file path needs the render option `localImages: { root }`, the folder it is read from.
export default function Example() {
return (
<Document>
<Page size={[320, 220]} className="p-6">
<Image src="./photo.jpg" fit="cover" className="h-36 w-full rounded-md" />
<Text className="mt-2 text-xs text-gray-500">Desert at dusk, cropped to fit by fit="cover".</Text>
</Page>
</Document>
);
}
<script setup lang="ts">
import { Document, Image, Page, Text } from '@inkoxide/vue';
</script>
<template>
<Document>
<Page :size="[320, 220]" class="p-6">
<Image src="./photo.jpg" fit="cover" class="h-36 w-full rounded-md" />
<Text class="mt-2 text-xs text-gray-500">Desert at dusk, cropped to fit by fit="cover".</Text>
</Page>
</Document>
</template>
<script lang="ts">
import { Document, Image, Page, Text } from '@inkoxide/svelte';
</script>
<Document>
<Page size={[320, 220]} class="p-6">
<Image src="./photo.jpg" fit="cover" class="h-36 w-full rounded-md" />
<Text class="mt-2 text-xs text-gray-500">Desert at dusk, cropped to fit by fit="cover".</Text>
</Page>
</Document>
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({
selector: 'app-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<ink-document>
<ink-page [size]="[320, 220]" class="p-6">
<ink-image src="./photo.jpg" fit="cover" class="h-36 w-full rounded-md" />
<ink-text class="mt-2 text-xs text-gray-500">Desert at dusk, cropped to fit by fit="cover".</ink-text>
</ink-page>
</ink-document>
`,
})
export class Example {}

| Prop | Type | Description |
|---|---|---|
src (required) | ImageSrc | Bytes (JPEG, PNG, GIF, WebP, SVG; a Uint8Array, Buffer or ArrayBuffer), a Blob (a File from a file input, read when the render starts), a data: URL, the id of an image passed in the render options, a file path (./logo.png, /srv/img/logo.png) or file: URL in a folder allowed by the render option localImages, an https: URL or a request allowed by the render option remoteImages, or a function or promise resolving to one of those. A string naming an image in the render options is that image, path or not. |
fit | 'fill' | 'contain' | 'cover' | 'none' | |
alt | string | The text the image copies and searches as: its alternative text, at most 1024 characters. In tagged output "" makes it decoration; PDF/UA requires alt on every other image. |
role | 'figure' | 'artifact' | 'artifact': decoration in tagged output, as alt="". |
It also takes the shared props break, wrap, minPresenceAhead, fixed, pages, href, bookmark, className, style, id, debug.
ImageBackground
A View with an image behind its children: the image fills the padding box (inside the borders), placed by fit and objectPosition, over the background colour and under the borders, clipped to the box and its borderRadius.
import { Document, ImageBackground, Page, Text } from '@inkoxide/react';
export default function Example() {
return (
<Document>
<Page size={[320, 200]} className="p-6">
<ImageBackground src="./photo.jpg" fit="cover" className="h-36 justify-end rounded-lg p-4">
<Text className="text-lg font-bold text-white">Desert at dusk</Text>
<Text className="text-xs text-white">Text over an image, clipped to the rounded box.</Text>
</ImageBackground>
</Page>
</Document>
);
}
<script setup lang="ts">
import { Document, ImageBackground, Page, Text } from '@inkoxide/vue';
</script>
<template>
<Document>
<Page :size="[320, 200]" class="p-6">
<ImageBackground src="./photo.jpg" fit="cover" class="h-36 justify-end rounded-lg p-4">
<Text class="text-lg font-bold text-white">Desert at dusk</Text>
<Text class="text-xs text-white">Text over an image, clipped to the rounded box.</Text>
</ImageBackground>
</Page>
</Document>
</template>
<script lang="ts">
import { Document, ImageBackground, Page, Text } from '@inkoxide/svelte';
</script>
<Document>
<Page size={[320, 200]} class="p-6">
<ImageBackground src="./photo.jpg" fit="cover" class="h-36 justify-end rounded-lg p-4">
<Text class="text-lg font-bold text-white">Desert at dusk</Text>
<Text class="text-xs text-white">Text over an image, clipped to the rounded box.</Text>
</ImageBackground>
</Page>
</Document>
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({
selector: 'app-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<ink-document>
<ink-page [size]="[320, 200]" class="p-6">
<ink-image-background src="./photo.jpg" fit="cover" class="h-36 justify-end rounded-lg p-4">
<ink-text class="text-lg font-bold text-white">Desert at dusk</ink-text>
<ink-text class="text-xs text-white">Text over an image, clipped to the rounded box.</ink-text>
</ink-image-background>
</ink-page>
</ink-document>
`,
})
export class Example {}

| Prop | Type | Description |
|---|---|---|
src (required) | ImageSrc | The image, in any form <Image src> takes. |
fit | 'fill' | 'contain' | 'cover' | 'none' | How the image fills the padding box: fill (default) stretches it, contain and cover keep its aspect ratio, none keeps its size. Wins over objectFit. |
It also takes the shared props break, wrap, minPresenceAhead, fixed, pages, href, bookmark, className, style, id, debug.
Synced from components/image.md in the inkoxide repository.