-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
Is your feature request related to a problem? Please describe.
We can render SVG to an image using code like that below. This works for paths etc, but images in the SVG don't render as there are no resource providers.
skia_stream = skia.Stream.MakeFromFile(svg_path)
skia_svg = skia.SVGDOM.MakeFromStream(skia_stream)
svg_width, svg_height = skia_svg.containerSize()
surface_width, surface_height = int(svg_width), int(svg_height)
surface = skia.Surface(surface_width, surface_height)
with surface as canvas:
skia_svg.render(canvas)
with io.BytesIO(surface.makeImageSnapshot().encodeToData()) as f:
img = Image.open(f)
img.save(path, quality=85)
Describe the solution you'd like
Skia provides capability for both file and base64 based href resources - an example of which you be seen here https://github.com/google/skia/blob/main/tools/viewer/SvgSlide.cpp
Specifically this code
auto predecode = skresources::ImageDecodeStrategy::kPreDecode;
auto rp = skresources::DataURIResourceProviderProxy::Make(
skresources::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str()), predecode),
predecode, ToolUtils::TestFontMgr());
fDom = SkSVGDOM::Builder()
.setFontManager(ToolUtils::TestFontMgr())
.setResourceProvider(std::move(rp))
.setTextShapingFactory(SkShapers::BestAvailable())
.make(*stream);
Describe alternatives you've considered
The only work around I've found is to manually parse the SVG and attempt to insert the image yourself - but this results proves challenging for anything but the most trivial files
Additional context
Metadata
Metadata
Assignees
Labels
No labels