Basically, I am trying to write a smart single command line that outputs base64 encoded strings instead of where the image path used to be. So:
background-image: url(path/to/my/image.png);
... will turn into:
background-image: url(data:image/png;base64,ABvR0β¦+tC==);
Usually I turn an image into its base64 encoded string via:
openssl enc -base64 -in path/to/my/image.png
Which displays base64 ... but with new lines in it. This is fixed by laying it through tr as follows:
openssl enc -base64 -in path/to/my/image.png | tr -d '\n'
which just prints a long base64 encoded string. Using pbcopy (on Mac OS), which is sent to the clipboard, for example:
openssl enc -base64 -in path/to/my/image.png | tr -d '\n' | pbcopy
It's nice that ad hoc replaces the random image with its base64 representation, but what I would like to do is automate the replacement of all url(path/to/whatever.ext) occurrences url(path/to/whatever.ext) in the file according to their corresponding base64 lines. Making sure that there are only actual paths and no uris data in this place outside the scope :)
I'm trying to replace sed stuff, but I'm stuck in its terrible documentation. It is not so difficult to find the occurrences in the url(β¦) pattern in the css file, but the bit between the brackets needs to be replaced by the output of this command, and I do not know if this is possible. So, here it is, help, or some pointers (do I also need to look into awk?). "You cannot do this without a proper script," of course also :)
Matijs
source share