How do you base-64 encode a PNG image for use in a data-uri in a CSS file?

前端 未结 6 1188
孤独总比滥情好
孤独总比滥情好 2020-11-28 06:47

I want to base-64 encode a PNG file, to include it in a data:url in my stylesheet. How can I do that?

I’m on a Mac, so something on the Unix command line would work

6条回答
  •  半阙折子戏
    2020-11-28 07:07

    This should do it in Python:

    import base64
    encoded = base64.b64encode(open("filename.png", "rb").read())
    

提交回复
热议问题