Skip to content

Commit

Permalink
Merge pull request #29 from alphagov/Image_mem_problem
Browse files Browse the repository at this point in the history
Image mem problem
  • Loading branch information
venusbb authored Jul 20, 2017
2 parents ee95e70 + 8e4e8fb commit c1ddf21
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ def validate_preview_request(json):
def png_from_pdf(pdf_endpoint, page_number):

output = BytesIO()
pdf = Image(blob=pdf_endpoint.get_data(), resolution=150)
image = Image(width=pdf.width, height=pdf.height)

try:
page = pdf.sequence[page_number - 1]
except IndexError:
abort(400, 'Letter does not have a page {}'.format(page_number))
with Image(blob=pdf_endpoint.get_data(), resolution=150) as pdf:
with Image(width=pdf.width, height=pdf.height) as image:
try:
page = pdf.sequence[page_number - 1]
except IndexError:
abort(400, 'Letter does not have a page {}'.format(page_number))

image.composite(page, top=0, left=0)
converted = image.convert('png')
converted.save(file=output)
image.composite(page, top=0, left=0)
converted = image.convert('png')
converted.save(file=output)

output.seek(0)

Expand Down

0 comments on commit c1ddf21

Please sign in to comment.