Files
butterfly/bin/ils
Albert Zeyer 6190f93c00 Update ils
fix `except`
2014-03-01 14:08:13 +01:00

32 lines
693 B
Python
Executable File

#!/usr/bin/env python
#Depends: pillow
#Broken: Too slow !
from PIL import Image
import os
import mimetypes
import base64
import io
print('\x1b]99;')
out = ''
for f in os.listdir(os.getcwd()):
mime = mimetypes.guess_type(f)[0]
if 'image' in (mime or ''):
try:
im = Image.open(f)
im.thumbnail((100, 100), Image.ANTIALIAS)
buf = io.BytesIO()
im.save(buf, im.format)
buf.seek(0)
out += '<img src="data:%s;base64,%s" alt="%s" />' % (
mime,
base64.b64encode(buf.read()).decode('ascii'),
f)
except Exception:
pass
print(out)
print('\x07')