Compare commits

...

2 commits

Author SHA1 Message Date
Ruben van de Ven
102fb78c02 Helper tool to fix json_appendable files when the screen size has changed during recording 2023-02-10 11:18:00 +01:00
Ruben van de Ven
58e869c969 Fix svg drawing generation 2023-02-09 14:00:21 +01:00
2 changed files with 69 additions and 1 deletions

68
app/fix_window_size.py Normal file
View 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

View file

@ -504,7 +504,7 @@ class DrawingHandler(tornado.web.RequestHandler):
if extension == "svg": if extension == "svg":
self.set_header("Content-Type", "image/svg+xml") self.set_header("Content-Type", "image/svg+xml")
self.write(drawing.get_animation().get_as_svg()) self.write(drawing.get_animation().get_as_svg())
if extension == "png": elif extension == "png":
self.set_header("Content-Type", "image/png") self.set_header("Content-Type", "image/png")
svgstring =drawing.get_animation().get_as_svg() svgstring =drawing.get_animation().get_as_svg()
self.write(cairosvg.svg2png(bytestring = svgstring)) self.write(cairosvg.svg2png(bytestring = svgstring))