Compare commits
2 commits
a1bc3acd5d
...
102fb78c02
Author | SHA1 | Date | |
---|---|---|---|
|
102fb78c02 | ||
|
58e869c969 |
2 changed files with 69 additions and 1 deletions
68
app/fix_window_size.py
Normal file
68
app/fix_window_size.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
"""
|
||||
Some recordings start with the wrong window size, probably because they were started on the laptop screen.
|
||||
This script modifies the opening dimensions and all subsequent viewbox elements to adhere to the new size.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
# TODO the whole script (still a copy)
|
||||
|
||||
logger = logging.getLogger("svganim.fixer")
|
||||
argParser = argparse.ArgumentParser(
|
||||
description="""Helper tool to fix the window size when the recording started with a smaller screen that full screen.
|
||||
|
||||
Beware, when used with a shell stdin redirect, do not point it towards the input file. That file will be truncated before reading!
|
||||
"""
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--input", type=str, help="Filename to run on (.json_appendable)"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--width", type=int, help="New width in px"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--height", type=int, help="New height in px"
|
||||
)
|
||||
args = argParser.parse_args()
|
||||
|
||||
|
||||
with open(args.input, "r") as fp:
|
||||
events = json.loads("[" + fp.read() + "]")
|
||||
extrabox = None
|
||||
for i, event in enumerate(events):
|
||||
if type(event) is list:
|
||||
# if event[1] != args.width or event[2] != args.height:
|
||||
# # correct default position
|
||||
# # extrabox = {"event": "viewbox", "viewboxes": [{
|
||||
# # 't': 0,
|
||||
# # 'x': (event[1] - args.width)/2,
|
||||
# # 'y': (event[2] - args.height)/2,
|
||||
# # 'width': args.width,
|
||||
# # 'height': args.height,
|
||||
# # }], 'original_size': [event[1], event[2]]}
|
||||
event[1] = args.width
|
||||
event[2] = args.height
|
||||
elif event["event"] == "viewbox":
|
||||
for key, box in enumerate(event['viewboxes']):
|
||||
# {"t": 1088912, "x": 0, "y": 0, "width": 2048, "height": 1152},
|
||||
box['x'] += (box['width'] - args.width)/2
|
||||
box['y'] += (box['height'] - args.height)/2
|
||||
box['width'] = args.width
|
||||
box['height'] = args.height
|
||||
event['viewboxes'][key] = box
|
||||
# elif event["event"] == "stroke":
|
||||
# event['points'] = [[p[0], p[1], p[2], p[3] + time_offset]
|
||||
# for p in event['points']]
|
||||
|
||||
if i>0:
|
||||
sys.stdout.write(",\n")
|
||||
sys.stdout.write(json.dumps(event))
|
||||
if extrabox:
|
||||
sys.stdout.write(",\n")
|
||||
sys.stdout.write(json.dumps(extrabox))
|
||||
extrabox = None
|
||||
|
||||
|
|
@ -504,7 +504,7 @@ class DrawingHandler(tornado.web.RequestHandler):
|
|||
if extension == "svg":
|
||||
self.set_header("Content-Type", "image/svg+xml")
|
||||
self.write(drawing.get_animation().get_as_svg())
|
||||
if extension == "png":
|
||||
elif extension == "png":
|
||||
self.set_header("Content-Type", "image/png")
|
||||
svgstring =drawing.get_animation().get_as_svg()
|
||||
self.write(cairosvg.svg2png(bytestring = svgstring))
|
||||
|
|
Loading…
Reference in a new issue