Repository navigation
feat(image): expose Image::intrinsic_size and scaled raster decoding via ImageCache::load_scaled - #1951
Merged
Conversation
Hona
force-pushed
the
feat/1361-svg-intrinsic-size-load-scaled
branch
from
November 24, 2026 14:46
1d1d8fa to
81b5ba7
Compare
…via ImageCache::load_scaled
Hona
force-pushed
the
feat/1361-svg-intrinsic-size-load-scaled
branch
from
November 24, 2026 14:50
81b5ba7 to
3137fb1
Compare
This was referenced Nov 24, 2026
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.
Fixes #1361
Fixes #702
Summary
Image::intrinsic_size(&self) -> Option<[f32; 2]>(crates/rune-image/src/lib.rs,svg.rs,from_url.rs):usvg::Tree::size()insidesvg_rgba_with_sizeduring existing SVG parsing across every SVG decode path (load,svg,load_mime,file,url, andload_scaled, on native andwasm32).[f32; 2]for rasters and returnsNonewhile pending or on error.Image::size()is unchanged.ImageCache::load_scaled(&self, bytes: impl Into<Arc<[u8]>>, size_pt: f32, scale: f32) -> Image(crates/rune-image/src/lib.rs,mips.rs,from_url.rs):(bytes, max_px)wheremax_px = (size_pt * scale).ceil().clamp(1.0, 8192.0)(non-finite inputs clamp to1).wasm32, browser-decoded formats downsample infrom_url::land_in_slicesbefore sliced mip generation; SVG/PNG/ICNS decode throughdecode_scaled.rune-image--decodestory inexamples/kit-gallery/src/stories/images.rs,?image-scaled-proofinexamples/web-hello/src/image_proof.rs, rustdoc examples,crates/rune/README.md,WEB.md,examples/README.md, andchangelog/unreleased/2026-11-24-svg-intrinsic-size-and-load-scaled.md.Architecture & Usage
flowchart LR A[ImageCache::load_scaled] --> B{is_svg?} B -- yes --> C[svg_rgba_with_size at max_px] C --> D[mip_chain + intrinsic: Some] B -- no --> E[Still frame-0 decode + EXIF orient] E --> F{longest > max_px?} F -- yes --> G[Linear-premultiplied area downsample] F -- no --> H[Keep original pixels] G --> I[mip_chain + intrinsic: None] H --> IOutside Standards Followed
HTMLImageElement.naturalWidth/naturalHeightand SVG 2 / CSS Images intrinsic sizing (resolved byusvg::Tree::size()).ImageCache::svg(bytes, size_pt, scale)/ImageCache::app_icon_scaledAPI shape alongside browsercreateImageBitmapresize and AppleCGImageSourceCreateThumbnailAtIndexfirst-frame, orientation-applied, never-upscale thumbnail semantics.