Hi everyone,
I’m facing an issue with transparent background images (in both WebP and PNG formats) on my Odoo 18 website. When I upload images, the thumbnails (e.g., on category pages) automatically add a white background. However, when I view the product page directly, the transparent background is displayed correctly.
Previously, on Odoo 17, I could avoid this issue by uploading images with a maximum resolution of 500x500 pixels in WebP format or any resolution in PNG format, but this workaround no longer works after upgrading to Odoo 18.
I cloned my production branch to staging in order to see if I can resolve the issue by having a look at source code and modifying it, but no success so far.
I found the following code snippet under src/odoo/addons/web_editor/controllers/main.py file:
# Background standardization
if bg is not None and bg.startswith('rgba'):
bg = bg.replace('rgba', 'rgb')
bg = ','.join(bg.split(',')[:-1])+')'
Commented out the last two lines, but that doesnt seem to help. This is all very new to me and I don't know Python.
I would like for my uploaded images to keep their transparent background through the whole site because I'm building a dark mode website and having white background on images does not work for me.
Does anyone know how to fix this issue? Any help with modifying the code or applying a better solution would be greatly appreciated!
Thanks in advance!
I just tested on Odoo's runbot and you're right, when you uploaded a transparent png and the converted webp will have a white background.
However, I think with previous comment, I found a temporary workaround. You can go to the website and edit the product page, replace the image with a transparent image and the resulting image will still be transparent. That's why I can do those screen captures as proof.