How do you base-64 encode a PNG image for use in a data-uri in a CSS file? November 9, 2022 by Tarik This should do it in Python: import base64 encoded = base64.b64encode(open("filename.png", "rb").read())