Skip to content

Improve image post rendering with aspect ratio and caption support - #55

Merged
KallynGowdy merged 1 commit into
devfrom
claude/inspiring-maxwell-bkm8dv
Sep 28, 2026
Merged

KallynGowdy merged 1 commit into
devfrom
claude/inspiring-maxwell-bkm8dv

Conversation

@KallynGowdy

Copy link
Copy Markdown
Contributor

Description

Refactors image post rendering in AppPostCard to better handle image dimensions and captions:

  • Aspect ratio preservation: Image covers now use the image's actual dimensions (from info.w and info.h) to maintain proper aspect ratio, with sensible clamping (0.5–3) to prevent extreme panoramas or tall images from rendering poorly. Falls back to 4:3 when dimensions are unavailable.
  • Caption support: Image posts can now display caption text when the body field differs from the filename (per Matrix spec). Captions are rendered below the image using the existing MText and RenderBody components.
  • Simplified image rendering: Replaced the MImage wrapper component with direct ImageContent usage, reducing indirection and making the component tree clearer.
  • CSS improvements: Updated .CoverImage styling to use aspectRatio CSS property, set maxHeight: 480px, and ensure proper overflow handling.

Extracted image-related logic into a new postImage.ts utility module with two pure functions:

  • getPostImageAspectRatio(info) — computes and clamps aspect ratio from image dimensions
  • hasImageCaption(content) — determines if an image event carries a caption

Both functions are covered by unit tests in postImage.test.ts.

Checklist:

  • I have read and understood the Contribution policy.
  • Added unit tests for new utility functions (postImage.test.ts)
  • Tests pass (npm test)

https://claude.ai/code/session_01WTpUJbH3od4yBtPRPKohFm

The cover image container had a fixed 250px height while the image
inside kept MImage's fixed 400px width and computed height, so it spilled
over the action bar. Render the image full-width with an aspect ratio
from its dimensions, and show the post's caption text below it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WTpUJbH3od4yBtPRPKohFm
@KallynGowdy
KallynGowdy merged commit fd04552 into dev Sep 28, 2026
4 checks passed
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.

2 participants