Skip to content

Commit

Permalink
Put the other Image Variable in with context
Browse files Browse the repository at this point in the history
  • Loading branch information
venusbb committed Jul 20, 2017
1 parent 18b4ee8 commit aa8083b
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions app/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,22 @@ def png_from_pdf(pdf_endpoint, page_number):
output = BytesIO()

with Image(blob=pdf_endpoint.get_data(), resolution=150) as pdf:
image = Image(width=pdf.width, height=pdf.height)
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))

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)

#pdf.destroy()

output.seek(0)

return {
'filename_or_fp': output,
'mimetype': 'image/png',
}
return {
'filename_or_fp': output,
'mimetype': 'image/png',
}


@preview_blueprint.route("/preview.json", methods=['POST'])
Expand Down Expand Up @@ -117,7 +114,3 @@ def view_letter_template(filetype):
return send_file(**png_from_pdf(
pdf, page_number=int(request.args.get('page', 1))
))




0 comments on commit aa8083b

Please sign in to comment.