core icon indicating copy to clipboard operation
core copied to clipboard

Setting group image converts to JPEG with black background

Open rosano opened this issue 3 years ago • 12 comments

  • Operating System (Linux/Mac/Windows/iOS/Android): macOS
  • Delta Chat Version: 1.29.0
  • Expected behavior: Image maintains transparency or uses white background
  • Actual behavior: Image loses transparency and/or uses black background
  • Steps to reproduce the problem: Upload a group image

Below is a sample image that can be used for testing. Because it's only a line drawing it ends up being completely black.

test

rosano avatar Nov 29 '22 08:11 rosano

Expected behavior: Image maintains transparency or uses white background

maintaining transparency should be done only as a workaround if it is the simpler solution "for now". transparency, shapes, alpha in user-avatars and webxdc-icons is a non-goal, resulting easily in lots of issues.

using a defined background color seems to be the better solution - and even if one could also have a png with only white lines, defaulting to a white background probably solves the majority of cases in practice.

r10s avatar Nov 29 '22 11:11 r10s

defaulting to a white background probably solves the majority of cases in practice.

Yes I was basically suggesting this, as I have used images from the web several times for group discussions, and each time I need to convert it to jpeg in order for it to appear correctly. Seems like it would be simple to solve.

using a defined background color seems to be the better solution

There could be a user defined colour but the app converts the image to jpeg with a black background, so any CSS styling would be overlapped.

rosano avatar Nov 29 '22 11:11 rosano

in desktop this is done by core, though on iOS the background is set to white instead of black, so maybe iOS has different logic for it?

Simon-Laux avatar Nov 29 '22 15:11 Simon-Laux

while we should check if core actually recodes png to jpg and if we can set another background for transparency on that way, i would say that it still makes sense if the UI use "white" as a background as a last resort. or is this complex in case of desktop?

r10s avatar Nov 29 '22 18:11 r10s

desktop just gives filename/path to core AFAIK, so nothing desktop can do in this case, right?

Simon-Laux avatar Nov 29 '22 18:11 Simon-Laux

it could maybe set css-background to "white" similar as done recently for webxdc icons.

r10s avatar Nov 29 '22 19:11 r10s

BTW: can not reproduce on desktop linux on 1.34 atleast on the device that sets it transparency stays

Simon-Laux avatar Nov 29 '22 19:11 Simon-Laux

using the image from above in the desktop 1.34.0 on ubuntu results in different rendering of the image:

  • white or transparent background in the edit dialog after selecting, black on reopening edit dialog
  • black background in the chatlist and in the chat title

Screenshot from 2022-11-29 22-01-40

~~if the background is set to white everywhere, things are already fine. that seems to be an easier solution as doing things in core, esp. as i think, the fallback "white" or "unique" background is needed anyway.~~ EDIT: while checking the css, indeed, the avatar is a jpeg, so there is not much desktop can do here. we have to pass the desired background to thumbnail generation somehow.

r10s avatar Nov 29 '22 21:11 r10s

so can reproduce too with the specific image rosano posted above, my own png with transparency remained transparent. maybe it has a flag set for background color or sth like that in the png metadata?

Simon-Laux avatar Nov 29 '22 21:11 Simon-Laux

my theory why it works on ios: the relatively large png is recoded to a smaller png (preserving transparency) already by the ios crop util. because of "already small enough, core does nothing, and as white is used as bg color things are fine. in case of desktop core recodes to jpg with replacing transparency to black (instead of white).

r10s avatar Nov 30 '22 09:11 r10s

Seems image crate encoder for JPEG accepts rgba images: https://github.com/image-rs/image/blob/f1e34f365133a33a27dac5bc59c93d1cfb34a37e/src/codecs/jpeg/encoder.rs#L471-L475

But I have not figured out what it does in this case just from looking at the code.

Guess we just need recode_to_size to convert the image to rgb without alpha channel and white background first.

link2xt avatar Sep 25 '23 15:09 link2xt

Related issue: https://github.com/image-rs/image/issues/2033

Septias avatar Nov 07 '23 12:11 Septias