forked from ethikkom/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.py
33 lines (26 loc) · 1.02 KB
/
renderer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
import os
from django.conf import settings
from ecs.utils.pathutils import tempfilecopy
from ecs.utils.pdfutils import pdf2pngs
def render_pages(identifier, filelike, private_workdir):
tiles = settings.MS_SHARED ["tiles"]
resolutions = settings.MS_SHARED ["resolutions"]
aspect_ratio = settings.MS_SHARED ["aspect_ratio"]
dpi = settings.MS_SHARED ["dpi"]
depth = settings.MS_SHARED ["depth"]
copied_file = False
if hasattr(filelike,"name"):
tmp_sourcefilename = filelike.name
elif hasattr(filelike, "read"):
tmp_sourcefilename = tempfilecopy(filelike)
copied_file = True
try:
for t in tiles:
for w in resolutions:
for page, data in pdf2pngs(identifier, tmp_sourcefilename, private_workdir, w, t, t, aspect_ratio, dpi, depth):
yield page, data
finally:
if copied_file:
if os.path.exists(tmp_sourcefilename):
os.remove(tmp_sourcefilename)