Skip to content

Conversation

@jmylchreest
Copy link

Add support for rendering images using terminal graphics protocols (Kitty, iTerm2, Sixel). Images are rendered inline in markdown output when a supported terminal is detected.

New options:

  • WithImageProtocol: set protocol (auto, kitty, iterm, sixel, none)
  • WithImageFetchRemote: enable fetching remote images via HTTP

Key implementation details:

  • Uses rasterm library for protocol detection and rendering
  • Deferred placeholder system prevents wordwrap from corrupting terminal escape sequences
  • Images bypass margin processing to preserve escape sequences
  • Graceful fallback to text-only rendering on error
  • Backward compatible: no changes when options are not set

Supported image sources:

  • Local files

  • Data URIs (base64 embedded)

  • Remote URLs (when ImageFetchRemote is enabled)

  • I have read CONTRIBUTING.md.

  • I have created a discussion that was approved by a maintainer (for new features).

I have not currently engaged in a further discussion, but I am following on from the now very outdated #175 and implemented this so that I could leverage this in glow - for which I have submitted another PR in the glow project that will link back to this PR.

Add support for rendering images using terminal graphics protocols
(Kitty, iTerm2, Sixel). Images are rendered inline in markdown output
when a supported terminal is detected.

New options:
- WithImageProtocol: set protocol (auto, kitty, iterm, sixel, none)
- WithImageFetchRemote: enable fetching remote images via HTTP

Key implementation details:
- Uses rasterm library for protocol detection and rendering
- Deferred placeholder system prevents wordwrap from corrupting
  terminal escape sequences
- Images bypass margin processing to preserve escape sequences
- Graceful fallback to text-only rendering on error
- Backward compatible: no changes when options are not set

Supported image sources:
- Local files
- Data URIs (base64 embedded)
- Remote URLs (when ImageFetchRemote is enabled)
@jmylchreest
Copy link
Author

A few discussions that might find be useful: #175 & charmbracelet/glow#211

- Add WebP image format support via golang.org/x/image/webp
- Update rasterm dependency to v1.1.2 (adds Rio/Ghostty detection)
- Add comprehensive test coverage for image rendering:
  - internal/images: 0% -> 83.6% coverage
  - ansi package: 80.9% -> 84.9% coverage
  - glamour package: 64% -> 69.4% coverage
- Add coverage.out to .gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant