fix(cli): preserve original image bytes when asset!() requests no transform (#5642)#5675
Open
singhlovepreet9 wants to merge 1 commit into
Open
fix(cli): preserve original image bytes when asset!() requests no transform (#5642)#5675singhlovepreet9 wants to merge 1 commit into
singhlovepreet9 wants to merge 1 commit into
Conversation
Comment on lines
+12
to
+17
| // If no image transformation was requested — no explicit output format and no | ||
| // manual resize — copy the source bytes verbatim instead of decoding and | ||
| // re-encoding. Re-encoding an already-optimized image (e.g. a hand-tuned PNG) | ||
| // can significantly *increase* its size, so by default we preserve the original | ||
| // bytes and only process the image when the user explicitly asks for a format | ||
| // or a size (see https://github.com/DioxusLabs/dioxus/issues/5642). |
There was a problem hiding this comment.
It looks like AI-generated explanatory text that was submitted without sufficient review or cleanup. Six lines of comments narrating such a simple guard in a small function is unreasonable.
Author
There was a problem hiding this comment.
Thanks for the feedback! You're completely right—the comment was unnecessarily verbose.I've shortened the comments to a single line, squashed the commits, and updated the PR. Let me know if everything looks good now!
This was referenced Jul 12, 2026
b077b5a to
eb91c04
Compare
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 #5642.
Problem
asset!("image.png")with no options re-encodes the image by default, which can significantly increase the size of an already-optimized PNG (the issue reports 193K → 976K).Root cause
An option-less
asset!(...)resolves toImageAssetOptions::default()=format: ImageFormat::Unknown,size: ImageSize::Automatic. Inprocess_image,format() == Unknownfalls into the catch-all(Ok(image), _) => image.save(output_path)arm, which decodes and re-encodes the image with theimagecrate's default PNG encoder — no optimization, and larger output for already-optimized sources.Fix
Add an early guard in
process_image: when no output format conversion and no manual resize are requested (Unknown+Automatic), copy the source bytes verbatim (the asset is still content-hashed by filename) instead of decoding and re-encoding. This matches the expected behavior in the issue — preserve the original bytes unless image processing is explicitly requested.Explicit
.with_format(...)/.with_size(...)paths are unchanged: those still resize/convert/optimize as before.Test
Added
opt::image::tests::default_options_preserve_source_bytes: it writes aBest-compressed source PNG carrying atEXtchunk (which a decode→re-encode drops), runsprocess_imagewith default options, and asserts the output is byte-identical to the source — so the test fails if the default path ever re-encodes again.Ran with
cargo +1.93.0 test -p dioxus-cli(repo MSRV 1.93).Note: @GPNaslund mentioned interest in the issue — happy to defer if they already have a fix in flight; posting this since no PR was up.