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

[bug] Losing transparency when converting png emoji to a static version #1295

Closed
rikkix opened this issue Jan 3, 2023 · 2 comments · Fixed by #1522
Closed

[bug] Losing transparency when converting png emoji to a static version #1295

rikkix opened this issue Jan 3, 2023 · 2 comments · Fixed by #1522
Labels
bug Something isn't working

Comments

@rikkix
Copy link

rikkix commented Jan 3, 2023

Description

When uploading a custom emoji with transparency in png format, the static version of the emoji will lose transparency info (and actually will turn into black).

Example

Original file at https://example.ltd/fileserver/XXX/emoji/original/XXX.png looks like:
image

Processed static file at https://example.ltd/fileserver/XXX/emoji/static/XXX.png looks like:
image

Related code

I have done an experiment that confirms the code in internal/media/png-stripper.go will cause this issue.
However, limited by my ability, I cannot figure out how to fix the bug in that file currently.

And I am curious that, since png file can never be an animated image, why do we need to decode the png file and encode that back like the code below?
But I haven't deeply dived to the whole project yet, so I am not sure if there is something thoughtless in my idea.

func deriveStaticEmoji(r io.Reader, contentType string) (*mediaMeta, error) {
var i image.Image
var err error
switch contentType {
case mimeImagePng:
i, err = StrippedPngDecode(r)
if err != nil {
return nil, err
}
case mimeImageGif:
i, err = gif.Decode(r)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("content type %s not allowed for emoji", contentType)
}
out := &bytes.Buffer{}
if err := png.Encode(out, i); err != nil {
return nil, err
}
return &mediaMeta{
small: out.Bytes(),
}, nil
}

Related issue(s) & PR(s)

#425
#487

Version

v0.6.0

@rikkix rikkix added the bug Something isn't working label Jan 3, 2023
@tsmethurst
Copy link
Contributor

png file can never be an animated image

It can be an animated image, there are animated pngs :) But yes indeed, losing transparency is a known issue, will have a look soon(tm) how this can be fixed.

@rikkix
Copy link
Author

rikkix commented Jan 3, 2023

png file can never be an animated image

It can be an animated image, there are animated pngs :) But yes indeed, losing transparency is a known issue, will have a look soon(tm) how this can be fixed.

I thought PNG and APNG were two totally separated formats both in MIME type and filename extension.
Thank you so much for pointing out my mistake!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants