Transparent backgrounds on PNG images lost in dynamic media URLs
When a user selects a PNG image with a transparent background via the standard Image component, the dynamic media image URL rendered transforms the transparent background to white instead. This creates an undesired white block around the image when used on a colored background.
The issue is that by default Scene7 DM renders PNGs with white background, and you have to pass a fmt=png-alpha argument to DM in order to preserve the transparent background.
Yes, an author can technically add fmt=png-alpha to the provided "Image Modifiers" field, but preserving the transparent background should really be the default, especially since using the image in lower environments potetnially w/o Dynamic Media and thus using the image directly from the AEM DAM will preserve the transparency.
In practice making all PNGs as png-alpha greatly increases file sizes served from Dynamic Media, which can incur a very large performance hit for larger images. So maybe setting that as a default is not a great idea. But is there a better solution for the overall problem of preserving PNG transparency in Dynamic Media that isnt so costly (or only applies when an image has transparency)?
Proposed Solution: Conditional PNG Transparency Detection
Rather than applying fmt=png-alpha to all PNGs (which would cause significant performance issues), we can automatically detect which PNGs actually have transparency using existing DAM metadata.
Key Insight: dam:Bitsperpixel metadata reliably indicates PNG transparency:
32bits = PNG with alpha channel (transparent) → Addfmt=png-alpha24bits = RGB PNG (opaque) → No format modifier needed8bits = Indexed PNG (opaque) → No format modifier needed
Implementation: Modify the Dynamic Media URL building logic in ImageImpl.java to automatically prepend fmt=png-alpha only when dam:Bitsperpixel = 32 for PNG assets.
Benefits:
- ✅ Preserves transparency automatically for transparent PNGs
- ✅ Maintains optimal performance for non-transparent PNGs
- ✅ Zero breaking changes - existing manual configurations still work
- ✅ Can be policy-controlled via
autoPreservePngTransparencysetting
This approach solves the transparency issue while completely avoiding the performance penalty since fmt=png-alpha is only applied when transparency actually exists.
nice, love the approach assuming it works!
@HitmanInWis Here is the PR https://github.com/adobe/aem-core-wcm-components/pull/2978.