Closed petterroea closed 2 months ago
@simsine That isn't the cause of the problem. We want to always store avatars as JPG to save disk space. The problem is that imagemagick doesn't like when the source image is PNG.
@simsine That isn't the cause of the problem. We want to always store avatars as JPG to save disk space. The problem is that imagemagick doesn't like when the source image is PNG.
Is it PIL.ImageOps that uses imagemagick?
@simsine my bad, i was mixing imagemagick and pillow.
I am talking about PIL. Basically the goal is this:
So as the stacktrace implies: OSError: cannot write mode P as JPEG. This means that the image has not been converted to RGB mode. This is supposed to happen on line 500. I was able to reproduce this locally by exporting a png with palettised colors as described here. Uploading this png failed as expected, this is because the parsed image with mode P does not contain the "transparency" key in im.info. Changing the "P" and "transparency" to or fixes this and allows us to upload the png normally.
@petterroea Do you know in which cases im.info contains "transparency"? As either using or or removing the check outright would fix this issue.
@simsine Good catch!
Many PNGs contain transparency, so i believe we need to support it. Are you able to make PIL convert the image to RGB(with image.convert('RGB')
or something?)?
For unit tests, can we ensure we test uploading with:
It seems we currently test RGB and RGBA PNGs: https://github.com/phoenixlan/phoenixapi-v1/tree/master/phoenixRest/tests/assets
Note that since we store as JPEG, the avatar already automatically strips away the transparency. We just need to support it because users may find themselves not being able to upload a photo due to transparency, but not being good enough at computers to strip it away.