Back to Qwen Code

Image Preview Guide

packages/desktop/apps/electron/resources/docs/image-preview.md

0.18.03.3 KB
Original Source

Image Preview Guide

This guide covers how to display image files inline using image-preview code blocks.

Overview

The image-preview block renders local image files inline in chat messages — showing the image in a fixed-height container with an expand button for fullscreen viewing.

FormatBest ForRendering
image-preview blockScreenshots, captures, visual diffsInline fit-to-container + fullscreen viewer
pdf-preview blockPDF reports and documentsFirst page inline + full navigation
html-preview blockRich HTML contentSandboxed iframe rendering

Key principle: Images are already files on disk. Reference them directly with an absolute path in src.

When to Use

Use image-preview when:

  • You have a local screenshot/capture file and want inline visual context
  • You want before/after visual comparisons in one response
  • A tool result generated or downloaded image files
  • The user asks to view an image directly in chat

Do NOT use image-preview when:

  • The content is a PDF (pdf-preview)
  • The content is rich HTML (html-preview)
  • The content is structured table data (datatable/spreadsheet)
  • The file format is unsupported in Chromium (often HEIC/HEIF/TIFF)

Basic Usage

Single Item

```image-preview
{
  "src": "/absolute/path/to/screenshot.png",
  "title": "Settings screen"
}
```

Multiple Items (Tabs)

Use items to show related images with tab navigation.

```image-preview
{
  "title": "Before / After",
  "items": [
    { "src": "/path/to/before.png", "label": "Before" },
    { "src": "/path/to/after.png", "label": "After" }
  ]
}
```

Content loads lazily on tab switch and is cached once loaded.

Config Fields

FieldRequiredTypeDescription
srcYes*stringAbsolute path to image file (single item mode)
titleNostringHeader title (defaults to "Image Preview")
itemsYes*arrayArray of image items with src and optional label
items[].srcYesstringAbsolute path to image file
items[].labelNostringTab label

*Either src (single) or items (multiple) is required. If both are present, items takes precedence.

Supported Formats

In-app preview supports Chromium-decodable formats:

  • PNG, JPG, JPEG, GIF, WebP, SVG, BMP, ICO, AVIF

Formats like HEIC/HEIF/TIFF may not render in-app. For those files, use external open.

Rendering Behavior

Inline Preview

  • Fixed 400px preview area
  • Image is rendered with object-contain (no cropping)
  • Expand button opens fullscreen overlay
  • Multi-item blocks show item navigator in the header

Fullscreen Overlay

  • Larger fit-to-container image view
  • Item navigation (arrows/dropdown) for multi-item sets
  • Copy path action in header
  • File path badge supports external open/reveal actions

Troubleshooting

"Loading..." shown indefinitely

  • Verify src is an absolute path
  • Confirm the file exists and is readable
  • Check that file extension is one of the supported formats

"Load Failed" error

  • File path may be invalid or access may be denied
  • Image may be corrupted
  • Format may not be decodable by Chromium

HEIC/TIFF doesn’t render

  • Expected for many environments
  • Open externally using the file path badge actions