Skip to content

Paint an image's inline background on its leaf instead of dropping it - #7465

Merged
chubes4 merged 1 commit into
trunkfrom
fix/7459-img-inline-background-image
Nov 24, 2026
Merged

chubes4 merged 1 commit into
trunkfrom
fix/7459-img-inline-background-image

Conversation

@chubes4

@chubes4 chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #7459.

Why

The Studio Bossa homepage paints its product photos ("Find your little Bossa.": Bossa Rio Table Lamp, Wave Vase) as atlas sprites. Each one is an <img> with a transparent 1×1 placeholder src, and the inline style paints the real photo:

<img src="data:image/png;base64,…1x1…" class="wave-atlas-photo"
     style="--wave-ratio:0.81;background-image:url(/media/rio-angles.jpg);background-position:17.2554% 91.4552%;background-size:355.556% 433.898%;aspect-ratio:0.813559 / 1">

Conversion dropped the background-image. InlineGeometry::className() (php-transformer/src/HtmlToBlocks/Style/InlineGeometry.php:480-487 on trunk) carries an inline url background only when the element has children or text, which an <img> never has. background-position and background-size still came through, but only because they override an author rule (inlineAuthorOverrideDeclarations), and they ended up on the synthetic figure (StyleResolver::presentationAttributes($image, …) from ImageLowering::imagePresentationAttributes(), ImageLowering.php:949 on trunk). The figure doesn't paint the image. The copied rio-angles.jpg / wave-vase.webp assets were never referenced, so the cards showed up as empty boxes.

The atlas is a sprite, so using it as the image src would show the whole sheet. The background declaration has to stay, and it has to paint the image's own box. That box can differ from the figure's: here author rules give the leaf height:220px, and at narrow widths width:calc(100% + 2*gutter) plus negative inline margins.

What changed

  • StyleResolver::imageLeafBackgroundProperties() (new): when an <img>'s inline background/background-image paints an image (url(), image-set() or a gradient), it returns the inline background longhands present (background, -image, -position, -size, -repeat, -origin, -clip, -attachment, -blend-mode).
  • StyleResolver::imageLeafPlacementClassName() forces those properties onto the existing image-leaf carrier (InlineGeometry::className(..., imageLeaf: true)). The carrier already targets .wp-block-image.X>img, keeps the inline-over-author tiering, and rewrites url() through resolvedAssetImageUrl().
  • ImageLowering::imagePresentationAttributes() excludes the same properties from the synthetic figure's carrier, so the crop isn't split across two boxes.
  • InlineGeometry::backgroundCarrierProperties() is now public, so there is still one list of background properties.

Output change

Before (trunk), the figure carries the crop and there is no image:

:root .be-inline-geometry-…{background-position:17% 91%;background-size:355% 433%}

After, the leaf paints the rewritten asset along with its crop:

.wp-block-image.be-inline-geometry-…>img,.wp-block-image.be-inline-geometry-…>a>img{background-image:url("website/media/atlas.jpg") !important;background-position:17% 91% !important;background-size:355% 433% !important}

On the imported site, the URL resolves to themes/<slug>/assets/website/media/rio-angles.jpg (HTTP 200).

Parity fixtures: unchanged (368 passed).

Evidence

Subset copy of the Bossa capture with /, imported through Studio CLI using SSI main (7c1f5190) dev packages built against trunk 85b9cf23baa (before) and this branch (after). Both were compared against the full capture with data-liberation 0.41.3 compare --screenshots.

width before (trunk) after (this PR)
390 pixel region 0,12624 390x480 (74 tiles) in core/group; 96,13296 240x240 (22 tiles) both gone
768 pixel region 0,12624 768x912 (206 tiles) in core/group; 144,13728 480x288 (48 tiles) both gone
1440 pixel region 528,12432 384x432 (57 tiles) in core/group; 960,12432 144x240 (14 tiles) both gone

All other regions at each width are identical between before and after. The remaining failures (internal-link 404s from the subset, the Δ10 page height, small text tiles) are unrelated. Visually, the lamp and vase cards now match the source screenshot at 768 and 1440.

Editor: opening the imported homepage in the block editor shows 344 blocks with 0 invalid, both atlas core/image blocks are valid, and the editor canvas paints rio-angles.jpg / wave-vase.webp on the images.

Tests

  • New tests/unit/image-inline-background-paint-rides-leaf.php: fails on trunk ("the inline background-image must paint the converted image leaf"), passes here. It checks that the leaf gets the asset and its crop and that the figure paints nothing.
  • composer lint: OK (PHPCS + PHPStan).
  • php tests/parity/run.php: 368 fixtures passed.
  • php tests/run.php: 2010 tests. 5 fail locally (artwork-slideshow, component-interactions, positioned-carousel-stage, header-button-box, shared-chrome-corpus), and they fail the same way on unmodified trunk in this PHP 8.5 environment.

AI disclosure: implemented by Claude (Opus) as a Franklin/Pi subagent; Chris Huber directed the work.

@chubes4
chubes4 force-pushed the fix/7459-img-inline-background-image branch from be77826 to ea6862c Compare November 24, 2026 02:05
@chubes4

chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Note on import-loop/corpus: this external replay ran twice on the same tree. I re-stamped the commit (be778269c34 → ea6862c3ec1) without changing the tree. The first run found no regressions on any corpus site and only reported a measurement error (could not measure: sdnunca: /@768). The second run reported worse on agency (1). With identical code that points to replay nondeterminism rather than this change, and #7461 shows the same agency (1) flag. All GitHub Actions checks pass.

@chubes4
chubes4 merged commit 87654ca into trunk Nov 24, 2026
14 of 15 checks passed
@chubes4
chubes4 deleted the fix/7459-img-inline-background-image branch November 24, 2026 03:08
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.

Inline background-image on an <img> is dropped during conversion

1 participant