Skip to content

fix(manganis): preserve original image bytes when no transform requested#5677

Closed
Functionhx wants to merge 1 commit into
DioxusLabs:mainfrom
Functionhx:fix/asset-png-reencode-5642
Closed

fix(manganis): preserve original image bytes when no transform requested#5677
Functionhx wants to merge 1 commit into
DioxusLabs:mainfrom
Functionhx:fix/asset-png-reencode-5642

Conversation

@Functionhx

Copy link
Copy Markdown

Fixes #5642.

asset!() re-encodes PNG through the image crate, inflating file size (193K→976K). Default-option images are decoded and re-compressed instead of copied verbatim.

Added early return in process_image() — fs::copy byte-for-byte when no format conversion or resize is requested. Explicit transforms still go through full decode→resize→encode pipeline.

3 observations from isolation review (non-blocking):

  • APNG now preserved instead of flattened
  • Corrupted-image detection moved from decode-time to copy-time
  • Zero-byte files pass through instead of erroring

…nsform

asset!("x.png") with no options resolves to ImageAssetOptions::default()
(format: Unknown, size: Automatic). In process_image that fell through to
image.save(), decoding and re-encoding the PNG with the image crate's default
encoder — which can significantly inflate an already-optimized image (#5642,
e.g. 193K -> 976K).

Add an early guard: when no output format and no manual size are requested,
copy the source bytes verbatim (still hashed by filename) instead of decoding
and re-encoding. Explicit .with_format()/.with_size() paths are unchanged.

Adds a regression test asserting default-options output is byte-identical to a
Best-compressed source PNG carrying a tEXt chunk (which a re-encode would drop).
@Functionhx
Functionhx requested a review from a team as a code owner July 11, 2026 17:31

@WaterWhisperer WaterWhisperer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR contains the exact same commit as #5675 (e2239b8), which was opened earlier by @singhlovepreet9 . Why was the same commit submitted again from a different account?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this looks exactly the same as #5675

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.

asset!() re-encodes PNG by default and significantly increases file size

3 participants