Repository navigation
Conversation
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
Fixes #806.
Uploaded images are re-encoded as WebP with GD, which drops the ICC color profile. A Display P3 screenshot keeps its P3 pixel values but loses the tag that says so, so browsers read the pixels as sRGB and the colors look washed out.
This draft carries the profile over instead of converting pixels:
CreateCommitImageFilesextracts the profile from the upload (JPEG APP2, including profiles split over several segments; PNG iCCP; WebP ICCP), validates it, re-encodes with GD exactly as today, then muxes the validated profile into the stored WebP as a VP8XICCPchunk. Every upload path goes through this action (commits, scheduled commits, message images), so one change covers all of them.@anttikissa you mentioned you might be looking into a fix as well — happy to close this in favor of yours if you have one in flight. Drafting this so the approach can be weighed first.
Screenshot taken in Chrome on macOS: the same Display P3 patches as the original upload, as stored by this PR, and as stored today with the profile dropped. Rows 1 and 2 match; row 3 is the washed-out rendering from #806.
Why transplanting instead of converting to sRGB
Converting P3 pixels to sRGB needs a color-managed transform. GD has none, and this file deliberately uses GD because Imagick writes source metadata back out. Transplanting needs no pixel math and no new extension: the validated profile is written into the WebP container around GD's output (a plain image gains the VP8X header; an image with alpha already has it, so only the ICC flag and chunk are added). Color-managed browsers then render the colors as authored.
Safety
Everything else is still stripped. A profile is carried only if it is a plausible display profile: 128 bytes to 1 MB, declared size matches its length,
mntrdevice class,RGBcolor space,acspsignature. Anything else is dropped, including a PNG profile that does not inflate. The existing "drops anything smuggled alongside the pixels" test still passes.Tests
New coverage in
CreateCommitImagesTest, in the same segment-injection style as the EXIF orientation test:Verified locally:
pest tests/Unit/Actions/CreateCommitImagesTest.php— 35 passed;CreateCommitImageFilescoverage 100.0%DatabaseSeederTest, which also fails on unmodifiedproductionin my environment, so it looks pre-existing and unrelatedpint --parallel --test— 940 files pass;rector --dry-run— clean;phpstan(level max) — no errors; type coverage — 100.0%bun run test:unit— 101 pass;bun run test:lint— 0 errors;bun run test:types— cleanwebpinforeportsICCP: 1with no errors anddwebpdecodes itsips): a screenshot-style PNG tagged Display P3 on the Mac was uploaded through the action, and the stored WebP reportsprofile: Display P3insips. Converting the original and the stored WebP to sRGB on the Mac gives the same colors (patch samples within 1 per channel, e.g.rgb(206,89,54)vsrgb(205,89,55)), while the same WebP with the profile stripped — today's GD output — renders as the raw untagged values (rgb(191,96,65))Docs
KNOWLEDGE_BASE.mdnow says the color profile is kept while other metadata is stripped.