mirror of
https://git.sdbs.cz/sdbs/pile.git
synced 2025-05-10 00:12:18 +00:00
fix if image generation fails
This commit is contained in:
parent
972f6b7b8e
commit
b52b173948
1 changed files with 7 additions and 3 deletions
|
@ -169,13 +169,17 @@ class BrandedImageView(View):
|
||||||
margin = 32
|
margin = 32
|
||||||
pile_image = Image.open(finders.find('pile_300dpi.png')).resize((256 - margin, 256 - margin))
|
pile_image = Image.open(finders.find('pile_300dpi.png')).resize((256 - margin, 256 - margin))
|
||||||
image = Image.open(document.image) if document.image else document.image_first_page
|
image = Image.open(document.image) if document.image else document.image_first_page
|
||||||
image.thumbnail((256, 256))
|
|
||||||
|
|
||||||
result = Image.new('RGBA', (256, 256), (0, 0, 0, 0))
|
result = Image.new('RGBA', (256, 256), (0, 0, 0, 0))
|
||||||
result.paste(image, ((256 - image.size[0]) // 2, (256 - image.size[1]) // 2))
|
|
||||||
|
if image:
|
||||||
|
image.thumbnail((256, 256))
|
||||||
|
result.paste(image, ((256 - image.size[0]) // 2, (256 - image.size[1]) // 2))
|
||||||
|
|
||||||
result.paste(pile_image, (margin//2, margin//2), pile_image)
|
result.paste(pile_image, (margin//2, margin//2), pile_image)
|
||||||
|
|
||||||
result = result.crop(result.getbbox())
|
if image:
|
||||||
|
result = result.crop(result.getbbox())
|
||||||
|
|
||||||
img_byte_arr = io.BytesIO()
|
img_byte_arr = io.BytesIO()
|
||||||
result.save(img_byte_arr, format='PNG')
|
result.save(img_byte_arr, format='PNG')
|
||||||
|
|
Loading…
Add table
Reference in a new issue