Fix: constrain image sizes in email notifications - #3637
Conversation
|
I am not sure if this pr fixes the issue properly. The report is about a mention, and it shows an avatar that is already around 100% max but this full display size is already too big. I think your PR is a nice improvement, but the issue is still existent!? |
|
@pfefferle thanks for the feedback. I checked the mention path (new-dm and new-mention both render the embed) and found two things that were still missing. The avatar in templates/embed.php now has inline The featured post image in templates/embed.php now has I kept Commit: 0bf2ae5 Would appreciate your review of this follow-up when you have a chance. |
pfefferle
left a comment
There was a problem hiding this comment.
Thanks for looking into the mention path, max-width:48px is the bit I was missing. 100% of a 600px container is still 600px, so that really was the problem.
Two things block this, plus one preference.
The changelog file sits in a subfolder, and changelogger only reads flat files in .github/changelog/, so the entry gets lost. And height="338" is a guessed aspect ratio that breaks exactly in the case this PR is about.
The preference: I would like to avoid inline style attributes here. templates/embed.php is the public oEmbed template, not a mail template, and inline styles beat assets/css/activitypub-embed.css silently. The width/height attributes already do the work when the style block is stripped, so I think we can get away without any inline style at all.
One note on the reasoning in the description: templates/emails/parts/header.php prints a <style> block too, in the same mail body as the embed one. A client that strips style blocks strips both. So the header rule is not what fixes the avatar, the attributes are. It is still useful for images inside the remote content, custom emoji and such, but the description credits it for the wrong thing.
Branch is a bit behind trunk, needs a rebase before merge.
0bf2ae5 to
2b34f17
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses email client rendering issues where remote avatars and embedded post images can appear at their native (often oversized) dimensions when <style> blocks are stripped or ignored, by adding explicit image sizing attributes and a defensive global email image rule.
Changes:
- Added explicit
width/heightattributes for avatar and follower icon images to keep sizes stable without CSS. - Added a
width="600"attribute for embedded preview images to preserve aspect ratio and avoid overflow in CSS-stripping clients. - Added a global
img { max-width: 100%; height: auto; }rule to the shared email header styles to constrain inline content images.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
templates/embed.php |
Adds explicit sizing attributes for embed avatar (48×48) and preview images (600px width). |
templates/emails/parts/header.php |
Adds a global img rule to constrain inline images inside email HTML. |
templates/emails/new-follower.php |
Adds explicit sizing attributes for follower icon (64×64). |
.github/changelog/3529-avatar-email-max-width |
Adds a patch-level changelog entry documenting the email image sizing fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
All five points are in the diff now, not just in the replies. The changelog file is flat, so changelogger actually reads it. The guessed One thing you do not need to worry about: the description has both the auto-changelog checkbox checked and a manual file. The workflow skips the body parsing when a changelog file is there, so there is no duplicate entry. Only the rebase is left, the branch is one commit behind trunk. Good to merge after that. Thanks a lot @faisalahammad! |
|
Maybe I was not precise... You would have to rebase your branch and push the updates @faisalahammad |
|
Rebased the branch on current trunk and pushed. No conflicts. Template and changelog content is unchanged from the version you approved, only the base moved. Checks are rerunning now. Ready for re-review when you have a moment. |
2b34f17 to
9e4fdd9
Compare
Constrain avatar and post images in email notifications so large remote avatars no longer render at native size and overflow the screen. Email clients often strip inline styles, so the size is now enforced with width/height attributes on the embed avatar, the new follower icon, and a global max-width rule in the shared email header style block. Fixes Automattic#3529
- Add inline max-width to the embed avatar so oversized remote avatars stay at 48px even when email clients strip style blocks - Add explicit dimensions to the embed featured image so post images fit the email width instead of overflowing Addresses PR feedback. Refs Automattic#3529
- Move changelog file out of fix/ subfolder so changelogger reads it. - Drop inline style on embed avatar; width/height attrs hold the 48px size. - Drop height="338" (wrong aspect for non-16:9) and inline max-width from the embed preview image; width="600" alone keeps the aspect ratio when the style block is stripped. Addresses PR feedback.
9e4fdd9 to
820cb9f
Compare
|
Branch updated again, rebased on the latest trunk (includes the podcast federation change). Same three commits, no content changes. Checks are rerunning. |
Fixes #3529
Proposed changes:
width/heightattributes to the embed avatar (48px) and the new follower icon (64px). The size now holds in the email client even when the style blocks are stripped, which is exactly the case the attributes target. When the CSS does load, the existing rules still apply without the inline version duplicating them.width="600"to the embed preview images. With the CSS loaded the.ap-preview imggrid sizing takes over; without it the browser keeps the aspect ratio from the width instead of squashing the image.img { max-width: 100%; height: auto; }rule to the shared email header style block. This does not fix the avatar (a client that strips the embed style block strips this one too) but it does constrain images inside the remote post content, such as custom emoji, that no selector covers today.Other information:
Logged-in test of email templates can't be automated here, so the fix was verified against the repository CSS and template output. The changes are template and CSS-only with no logic change, so no PHPUnit coverage is added.
Testing instructions:
npm run env-start).<style>blocks (for example Gmail).Changelog entry
A changelog entry was added manually as
.github/changelog/3529-avatar-email-max-width.Changelog Entry Details
Significance
Type
Message
Fixed oversized avatar and post images in email notifications from remote users. Avatars and inline images now resize to fit the email width instead of overflowing the screen.