Well you wouldn’t be able to do it without knowing the image size but I’m wondering in what use case you don’t know the image size?
I wouldn’t do this on the frontend side, it’s probably easier to get the original image width/height and send it to the frontend in one go with the
Probably not using CSS variables alone but using the new
contrast function in CSS4 Colors you could do something like:
color: color(var( — backgroundColor) contrast(50%));