import asyncio import io import PIL.Image import wand.color import wand.image __all__ = ["render_svg_image"] def _render_svg_image(svg: bytes, width: int, height: int) -> PIL.Image.Image: with wand.image.Image( blob=svg, format="svg", width=width, height=height, background=wand.color.Color("#ffffff00"), ) as image: image = PIL.Image.open( io.BytesIO(image.make_blob("png")), ) image = image.convert("RGBA") return image async def render_svg_image( svg: bytes, width: int, height: int ) -> PIL.Image.Image: loop = asyncio.get_running_loop() return await loop.run_in_executor( None, _render_svg_image, svg, width, height )