b64-image: Convert an image to CSS/HTML base64 foo
This commit is contained in:
parent
c8be409689
commit
03a51c2e04
1 changed files with 22 additions and 0 deletions
22
b64-image
Executable file
22
b64-image
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# Convert an image to CSS/HTML base64 foo
|
||||||
|
|
||||||
|
from __future__ import division, print_function
|
||||||
|
import base64
|
||||||
|
import magic
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if not hasattr(magic, "from_file"):
|
||||||
|
print("wrong magic module installed? try pip install python-magic")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if len(sys.argv[1:]) == 0:
|
||||||
|
print("Usage: " + sys.argv[0] + " IMAGE.PNG ...")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for filename in sys.argv[1:]:
|
||||||
|
mimetype = magic.from_file(filename, mime=True)
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
encoded = base64.b64encode(f.read())
|
||||||
|
print("url(data:{};base64,{})".format(mimetype, encoded))
|
Loading…
Add table
Add a link
Reference in a new issue