From f3b8deb63b5f4bb1ebdcf03675e1701dbd6d524c Mon Sep 17 00:00:00 2001 From: derchris Date: Sun, 20 Jan 2019 06:41:57 +0100 Subject: [PATCH] add option to render using imagemagick --- README.md | 4 ++-- make.py | 4 ++++ renderlib.py | 21 +++++++++++++++------ requirements.txt | 5 +++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d42a4d2..3bed373 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ $ pip3 install -r requirements.txt ##### Debian -On debian, for python lxml dependencies: +On debian you need to install ImageMagick and Python lxml dependencies: ``` -sudo apt-get install libxml2-dev libxslt1-dev +sudo apt-get install libmagickwand-dev libmagickcore5-extra libxml2-dev libxslt1-dev ``` Quick start diff --git a/make.py b/make.py index fca6911..0650619 100755 --- a/make.py +++ b/make.py @@ -48,6 +48,10 @@ parser.add_argument('--skip-frames', action="store", default=None, type=int, hel Skip first n frames e.g. to quickly rerender during debugging. Usage: ./make.py yourproject/ --debug --skip-frames 300 ''') +parser.add_argument('--imagemagick', action="store_true", default=False, help=''' + Render frames using ImageMagick instead of Inkscape. + Usage: ./make.py yourproject/ --imagemagick + ''') if len(sys.argv) < 2: parser.print_help() diff --git a/renderlib.py b/renderlib.py index a4e9fda..2fb82c4 100644 --- a/renderlib.py +++ b/renderlib.py @@ -13,6 +13,7 @@ import cssutils import logging import subprocess from urllib.request import urlopen +from wand.image import Image # Frames per second. Increasing this renders more frames, the avconf-statements would still need modifications fps = 25 @@ -168,12 +169,20 @@ def rendertask(task): width = 1024 height = 576 - # invoke inkscape to convert the generated svg-file into a png inside the .frames-directory - cmd = 'cd {0} && inkscape --export-background=white --export-background-opacity=0 --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height) - errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT) - if errorReturn != '': - print("inkscape exitted with error\n" + errorReturn) - # sys.exit(42) + if args.imagemagick: + # invoke imagemagick to convert the generated svg-file into a png inside the .frames-directory + infile = '{0}/.gen.svg'.format(task.workdir) + outfile = '{0}/.frames/{1:04d}.png'.format(task.workdir, frameNr) + with Image(filename=infile) as img: + with img.convert('png') as converted: + converted.save(filename=outfile) + else: + # invoke inkscape to convert the generated svg-file into a png inside the .frames-directory + cmd = 'cd {0} && inkscape --export-background=white --export-background-opacity=0 --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height) + errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT) + if errorReturn != '': + print("inkscape exitted with error\n" + errorReturn) + # sys.exit(42) # increment frame-number frameNr += 1 diff --git a/requirements.txt b/requirements.txt index 478edac..d395c00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ cssutils==1.0.1 -lxml==3.4.4 -svg.path==2.2 +lxml==4.2.5 +svg.path==3.0 +Wand==0.5.0