Merge branch 'masto-notifications' into 'master'

gifs and layout fixes

See merge request bhowell/the-screenless-office!2
workspace
Brendan Howell 6 years ago
commit a5831f0d7d

@ -353,10 +353,15 @@ class Bureau(object):
"""
# TODO: make printer id/width configured and easy
prn = printer.Usb(0x416, 0x5011, in_ep=0x81, out_ep=0x03)
if type(img) is PIL.Image.Image:
im = img
else:
im = PIL.Image.open(img)
# NOTE: might be worth tring to push up brightness
im = PIL.ImageOps.equalize(im) # stretch histogram for nicer dither
im.thumbnail((576, 576), PIL.Image.ANTIALIAS) # resize to fit printer
im.thumbnail((576, 1024), PIL.Image.ANTIALIAS) # resize to fit printer
prn.image(im, impl="bitImageColumn") # not using this impl crashes ??
@add_command("test")

@ -1,6 +1,13 @@
import glob
import math
import mimetypes
import os
import subprocess
import urllib
from bureau import Bureau, add_command
from PIL import Image
from bureau import Bureau, add_command, add_api
class Humor(Bureau):
@ -24,6 +31,59 @@ class Humor(Bureau):
jux = str(subprocess.check_output("/usr/games/fortune"), encoding="UTF-8")
self.print_small(jux)
@add_api("gif", "Moving Picture")
def print_gif(self, data):
"""
Prints out a series of image frames which can be viewed in lively
motion on any standard zoetrope. (Ø200mm)
"""
# download the video file
d_url = data["url"]
filename, headers = urllib.request.urlretrieve(d_url)
print("fetching", d_url, filename)
# make sure we have a legit filename
ext = mimetypes.guess_extension(headers["Content-Type"])
if not filename.endswith(ext):
os.rename(filename, filename + ext)
filename = filename + ext
print("renamed to ", filename)
# if we have something that's a gif or webp (png?) then
# just print 12 frames
if filename.endswith(("gif", "webp")):
print("gif stuff")
img = Image.open(filename)
print(img.n_frames)
grab_frame = 0
out_frame = 0
in_len = float(img.n_frames)
# TODO: deal with frame counts lower than 12
# and maybe a different algo that includes endpoints
for frame in range(img.n_frames):
img.seek(frame)
if grab_frame == frame:
img_rotated = img.rotate(90, expand=True)
self.print_small_image(img_rotated)
out_frame += 1
grab_frame = math.ceil(out_frame * in_len / 12)
else:
# how many frames do we have?
cli = "ffprobe -i " + filename + \
" -show_format -v quiet | sed -n 's/duration=//p'"
vid_len = str(subprocess.check_output(cli), encoding="UTF-8")
print("video len: " + vid_len)
# TODO: if vid_len is not a number handle this error
# lengthen/shorten it to 12 frames
# dump frames to temp files
cli = "ffmpeg -i" + filename + " -vf fps=12/" + vid_len +\
" thumb%02d.png"
# print em out!
self.print_small("")
def main():
ha = Humor()

@ -49,6 +49,10 @@
width: 50%;
height: 50%;
}
.endnotebc {
width: 50%;
height: 50%;
}
</style>
<body>
<h1>${title}</h1>

@ -175,7 +175,7 @@ class Publications(Bureau):
#TODO: make this barcode inline thing a util method
encoded_svg = b64encode(bytes(svg, 'utf-8')).decode()
encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg
svg = '<img src="%s"/>' % encoded_data
svg = '<img class="endnotebc" src="%s"/>' % encoded_data
footnote.append(lxml.html.fromstring(svg))
html.append(footnote)

Loading…
Cancel
Save