Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong conversion to JPEG instead of PNG when WEBP/AVIF is not supported (fixes images with alpha channels) #36611

Closed
wants to merge 1 commit into from

Conversation

thexpand
Copy link

@thexpand thexpand commented May 1, 2022

Change the fallback contentType from JPEG to PNG.
This way even if the unsupported contentType (webp/avif) has an alpha channel, it won't turn black.

Fixes #35674

It's in direct relation and extension to a previously resolved issue #20794 fixed by PR #35190

This way even if the unsupported contentType (webp/avif) has an alpha channel, it won't turn black.
@balazsorban44
Copy link
Member

I think this might not be the right approach as PNGs are generally bigger than JPEGs and would penalize use cases where transparency is not an issue.

We should somehow detect if an image has transparency and only convert it to PNG if it does instead.

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Did you compare the size before and after?

This will likely increase the size so its not desirable.

Instead, the image should be analyzed for transparency/alpha and only use PNG in that case.

Lastly, we need tests to prove this is working as expected.

@thexpand
Copy link
Author

thexpand commented May 2, 2022

@styfle Is there a standard way somewhere else in next/image or in next in general to detect transparency in an image? If there is, probably it's better to reuse it, otherwise, we'll have to analyze the bytes data stream with DataView somehow.

@styfle
Copy link
Member

styfle commented May 2, 2022

I don't think we have any existing logic for this behavior

kodiakhq bot pushed a commit that referenced this pull request May 2, 2022
Fixes the GitHub CODEOWNERS pattern matching which previously missed adding me to #36611
@ijjk ijjk force-pushed the canary branch 3 times, most recently from df8579c to 47e5ebe Compare October 25, 2022 16:15
@ijjk ijjk force-pushed the canary branch 2 times, most recently from e078ebe to 6b863fe Compare December 2, 2022 05:49
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Going to close this as stale, feel free to open fresh PR considering above feedback if interested!

@ijjk ijjk closed this Jun 15, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants