[Backport] Fixing svg processors

remotes/origin/live-notifications
Alejandro Alonso 2017-03-17 12:32:31 +01:00 committed by David Barragán Merino
parent 8958e6844c
commit 38423ff57e
1 changed files with 4 additions and 1 deletions

View File

@ -34,13 +34,16 @@ from io import BytesIO
try: try:
from cairosvg.surface import PNGSurface from cairosvg.surface import PNGSurface
def _accept(prefix):
return "svg" in str(prefix.lower())
def svg_image_factory(data, *args): def svg_image_factory(data, *args):
png_data = PNGSurface.convert(data.read()) png_data = PNGSurface.convert(data.read())
return PngImageFile(BytesIO(png_data)) return PngImageFile(BytesIO(png_data))
Image.register_mime("SVG", "image/svg+xml") Image.register_mime("SVG", "image/svg+xml")
Image.register_extension("SVG", ".svg") Image.register_extension("SVG", ".svg")
Image.register_open("SVG", svg_image_factory) Image.register_open("SVG", svg_image_factory, _accept)
except Exception: except Exception:
pass pass