Compare commits

...

2 Commits

Author SHA1 Message Date
Raphael Michel
1cbeb4fa77 Add comment 2025-01-21 15:03:28 +01:00
Raphael Michel
eeae05773e Invoice rendering: Remove logos from transparency 2025-01-17 17:27:33 +01:00
2 changed files with 15 additions and 0 deletions

View File

@@ -388,6 +388,15 @@ class ClassicInvoiceRenderer(BaseReportlabInvoiceRenderer):
except:
logger.exception("Can not resize image")
pass
try:
# Valid ZUGFeRD invoices must be compliant with PDF/A-3. pretix-zugferd ensures this by passing them
# through ghost script. Unfortunately, if the logo contains transparency, this will still fail.
# I was unable to figure out a way to fix this in GhostScript, so the easy fix is to remove the
# transparency, as our invoices always have a white background anyways.
ir.remove_transparency()
except:
logger.exception("Can not remove transparency from logo")
pass
canvas.drawImage(ir,
self.logo_left,
self.pagesize[1] - self.logo_height - self.logo_top,

View File

@@ -39,6 +39,12 @@ class ThumbnailingImageReader(ImageReader):
self._data = None
return width, height
def remove_transparency(self, background_color="WHITE"):
if "A" in self._image.mode:
new_image = Image.new("RGBA", self._image.size, background_color)
new_image.paste(self._image, mask=self._image)
self._image = new_image.convert("RGB")
def _jpeg_fh(self):
# Bypass a reportlab-internal optimization that falls back to the original
# file handle if the file is a JPEG, and therefore does not respect the