spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

Maintaining transparency from PNGs #264

Closed dhmax88 closed 5 months ago

dhmax88 commented 5 months ago

Hi! Is it possible to maintain transparency on PNG images, they are being converted to avif and webp but have black backgrounds?

aelvan commented 5 months ago

Hi,

In regards to AVIF, this appears to be a bug in certain compiled ImageMagick versions, see:

https://askubuntu.com/questions/1411869/creating-avif-or-heic-images-with-transparency-does-not-work-with-imagemagick-in https://bugs.launchpad.net/ubuntu/+source/imagemagick/+bug/1980124 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040307

I've confirmed that this happens both when using Imager X, Craft's native transforms, and Imagick directly, on the latest version of ddev.

In regards to WebP, I don't see any such issues. Have you tested if it's really the case that WebP also has a black background, or might it be that you got served the AVIF file through a picture tag?

dhmax88 commented 5 months ago

Thanks André

You’re correct - we ended up removing the avif transform and sticking to just webp. All is transparent as expected!

On Sat, 8 Jun 2024 at 10:47, André Elvan @.***> wrote:

Hi,

In regards to AVIF, this appears to be a bug in certain compiled ImageMagick versions, see:

https://askubuntu.com/questions/1411869/creating-avif-or-heic-images-with-transparency-does-not-work-with-imagemagick-in https://bugs.launchpad.net/ubuntu/+source/imagemagick/+bug/1980124 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040307

I've confirmed that this happens both when using Imager X, Craft's native transforms, and Imagick directly, on the latest version of ddev.

In regards to WebP, I don't see any such issues. Have you tested if it's really the case that WebP also has a black background, or might it be that you got served the AVIF file through a picture tag?

— Reply to this email directly, view it on GitHub https://github.com/spacecatninja/craft-imager-x/issues/264#issuecomment-2155908408, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHMEL3F7AKYSUAQBJGXLG3ZGLHJJAVCNFSM6AAAAABI73EGWWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJVHEYDQNBQHA . You are receiving this because you authored the thread.Message ID: @.***>

aelvan commented 5 months ago

Btw, it seems like transparency works perfectly fine when using a command line encoder like cavif, which can be configured to be used as a custom encoder in Imager, see the docs.

Not a perfect solution, but maybe helpful if you or someone else really want to deliver transparent avifs. :)