Skip to content

Fix alpha encoding in extended-range PNG snapshots - #281

Closed
pixelmatrix wants to merge 1 commit into
getsentry:mainfrom
pixelmatrix:fix/png-alpha-encoding
Closed

pixelmatrix wants to merge 1 commit into
getsentry:mainfrom
pixelmatrix:fix/png-alpha-encoding

Conversation

@pixelmatrix

Copy link
Copy Markdown
Contributor

We were seeing artifacts on partially transparent pixels in our snapshot tests, and after some research, found that UIImage.pngData() causes this reliably. Exporting using ImageIO does not have the same problem. I've forked this and implemented a fix for us, and wanted to contribute it back, in case it's useful.

Before After
Linear_DraftStack swift_Draft_Card Linear_DraftStack swift_Draft_Card-2

@jamieQ

jamieQ commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

@pixelmatrix thanks a lot for raising this! I'm looking into adopting your general strategy via #284 and make a few minor tweaks.

Out of curiosity, have you filed a feedback for this by chance? It seems quite surprising to me that the "deafult" PNG encoding path would apparently lose color/alpha info like this, so feels like something that should be fixed in the frameworks.

Edit: For the record, I filed FB25109021 and opened this dev forum thread to see if this can be addressed at a framework level.

jamieQ added a commit that referenced this pull request Oct 8, 2026
Preserve UIImage orientation metadata when exporting through ImageIO. Use small color-aware regression fixtures and a strict expected-failure check to flag a future UIKit alpha fix.

Refs #281
jamieQ added a commit that referenced this pull request Oct 8, 2026
* Fix alpha encoding in extended-range PNG snapshots

* fix(png): Preserve orientation and strengthen encoding coverage

Preserve UIImage orientation metadata when exporting through ImageIO. Use small color-aware regression fixtures and a strict expected-failure check to flag a future UIKit alpha fix.

Refs #281

* test(png): Simplify UIKit alpha canary assertions

* test(png): Simplify image encoding regression checks

Compare decoded pixels with the source image instead of parsing 16-bit PNG samples.

* test(png): Check orientation independently of UIKit metadata

---------

Co-authored-by: Josh Pyles <josh@linear.app>
@jamieQ

jamieQ commented Oct 8, 2026

Copy link
Copy Markdown
Member

Closing in favor of #284. Version 0.20.0 should have the workaround – thanks again!

@jamieQ jamieQ closed this Oct 8, 2026
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.

2 participants