feat(engine): export LoadImages for non-raster painters - #114
Merged
Conversation
…ter target loadImages — fetch, decode, budget and viewport-fit every <img> and inline <svg>, returning the intrinsic sizes layout needs and the bitmaps a painter needs — was unexported, so a consumer running the engine's own cascade and layout but painting elsewhere (go-pdfkit/html2pdf, which writes a vector PDF) had no way to size or draw images short of re-implementing all of that. LoadImages is a thin exported entry point over the same code path RenderDocument uses, so such a consumer lays out and draws images exactly as the built-in raster canvas does. Covered by TestLoadImagesExported: a data:-URI PNG round-trips offline into both maps keyed by its element, at its 8x8 intrinsic size, while a display:none and a src-less <img> land in neither. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
3 tasks
tannevaled
added a commit
to go-pdfkit/html2pdf
that referenced
this pull request
Sep 4, 2026
…dImages (#2) Both image gaps the README documented close in one step. Rather than re-implement fetch/decode/budgeting here, Export calls the engine's own pipeline — Engine.LoadImages, exported for exactly this in go-webengine/engine#114 — hands its intrinsic-size map to layout.LayoutDocument and its bitmap map to the PDF painter. An image is therefore laid out at, and drawn at, precisely the size the engine's raster canvas would use, and an inline <svg> arrives already rasterised by the same path. Options.BaseURL resolves a relative src; a failed fetch/decode leaves that element out, as on the raster canvas. This is the one place Export touches the network. Corpus, this run: embedded image XObjects — Wikipedia (Go) 30, countries list 10, go.dev/blog 40, Hacker News 6, pkg.go.dev/net/http 88, react.dev 166; text length unchanged on every page. Two costs recorded in CORPUS.md: react.dev grew to 12 pages / 9 MB (166 icon SVGs stored as raw FlateDecode RGB, no bitmap dedup yet — the obvious next saving), and the Render column is now network-bound for image-bearing pages since fetch runs inside Export. Also pins go-webengine/engine to the merged #114 commit and drops the temporary local replace used during development. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
🤖 Generated with Claude Code