Detect transparency in image resource with imageConfig (?)

I have been working towards a render-image hook that lazyloads images, with a low-resolution placeholder embedded as base64. (see related code)

What I want to do, is to detect transparency in an image resource. Is this even possible?

I wonder if any Hugo wizards know of a way to determine whether an image resource has opacity (either full, or alpha). Digging into the documentation, imageConfig’s .ColorModel property seemed promising, but I am getting inconsistent results and do not know how to read the output.

I wish to avoid the placeholder for images that have transparency, because the fully loaded image won’t be able to accurately cover its background. I also wish to avoid using JavaScript to replace the src attribute. So far this approach works great for opaque images.

Trying ColorModel, in the case of PNG8 files with a limited palette, sets of what appears to be RGBA values are returned (e.g. {0 0 0 255} …) but the A is always opaque (255). In the case of PNG24 and JPEG files, I get a single hex value, such as 0xd72140 which I have no idea what it represents.

For “complicated” questions like this that don’t have much to do with Hugo I always go to stackexchange. There is a thread here about this, but I am not sure if that helps you. In the end this seems to be nothing that you can do while piping in Hugo imho, probably as a script before hugo runs.

Or here specifically Go.

Thank you for the leads!
I am not currently interested to introduce external dependencies in the mix. I’ll try opening a feature request, in case there’s more people interested in something like this. Perhaps even read a file’s headers as in PNG it’s where this information would be stored at.

Edit: Proposal in Issue 7857