Created
May 14, 2015 16:32
-
-
Save ale-rt/73b21d1bde590856e4e9 to your computer and use it in GitHub Desktop.
Script that creates css rules to add background png images with data-uris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PIL import Image | |
from base64 import encodestring | |
import sys | |
template = '''.%(classname)s { | |
width: %(width)spx; | |
height: %(height)spx; | |
background-repeat: no-repeat; | |
background-image: url(data:image/png;base64,%(data)s); | |
} | |
''' | |
for f in sys.argv[1:]: | |
width, height = Image.open(f).size | |
img_data = open(f).read() | |
data = { | |
'classname': f.partition('.')[0], | |
'data': ''.join(encodestring(img_data).split()), | |
'width': width, | |
'height': height, | |
} | |
print template % data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment