[Backport] Fix problem with fetch urls from cairoSVG

remotes/origin/3.4.0rc
Jesús Espino 2017-07-20 13:41:11 +02:00
parent d1dd3631f9
commit 0ddbf27d5c
1 changed files with 8 additions and 1 deletions

View File

@ -33,15 +33,22 @@ from io import BytesIO
# SVG thumbnail generator # SVG thumbnail generator
try: try:
from cairosvg.surface import PNGSurface from cairosvg.surface import PNGSurface
from cairosvg.url import fetch
import magic import magic
def url_fetcher(url, resource_type):
if url.startswith("data:"):
return fetch(url, resource_type)
return b""
def svg_image_factory(fp, filename): def svg_image_factory(fp, filename):
mime_type = magic.from_buffer(fp.read(1024), mime=True) mime_type = magic.from_buffer(fp.read(1024), mime=True)
if mime_type != "image/svg+xml": if mime_type != "image/svg+xml":
raise TypeError raise TypeError
fp.seek(0) fp.seek(0)
png_data = PNGSurface.convert(fp.read()) png_data = PNGSurface.convert(fp.read(), url_fetcher=url_fetcher)
return PngImageFile(BytesIO(png_data)) return PngImageFile(BytesIO(png_data))
Image.register_mime("SVG", "image/svg+xml") Image.register_mime("SVG", "image/svg+xml")