If you, or someone else facing a similar problem in future are open to PHP.
(I know you said HTML/CSS, but maybe you are already using PHP in the backend)
Here is a PHP solution:
I got it from the PHP GD library and added some variable to automate the process...