Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed SVG images #107

Open
byorgey opened this issue Mar 2, 2019 · 3 comments
Open

Embed SVG images #107

byorgey opened this issue Mar 2, 2019 · 3 comments

Comments

@byorgey
Copy link
Member

byorgey commented Mar 2, 2019

Right now it is possible to embed raster images (PNG, JPG, ...) but not other SVG images, although the SVG format itself supports embedded SVGs perfectly well, either via a nested <svg> tag or via an <image ... xlink:href="..."> tag (corresponding to the existing embedded/external distinction in diagrams).

While researching the best way to support this I'm realizing that diagrams' whole system of support for images is very much biased towards raster images. The SVG backend has an instance for DImage Embedded which definitely represents a raster image; it also has a special loadImageSVG which goes via ImageNative, but it also only supports PNG or JPEG, and ends up embedding them in a base64-encoded data URI. I think trying to shoehorn embedded SVG into this is going to be annoying.

Instead, I think the simplest approach is to simply add a new kind of embedded SVG primitive, specific to the SVG backend. It would be easiest to have it work via the xlink approach but inlining the contents of another SVG should be possible too.

@igormoreno
Copy link
Contributor

That's exactly what I need! I have a complicated SVG image and I would like to turn it into an element to be manipulated in the diagram. Basically, I would like to use SVG as input (not only output) for diagrams. I guess that should be a feature in svg-builder, no? I found svg-tree but I don't think I can use it, right? Maybe if both had a general XML representation behind or provided a way to convert from/to it (like svg-tree seems to have) then it would open more possibilities for reuse/interoperability, no?

What do you suggest I do? Should I turn the SVG into a PNG?

@byorgey
Copy link
Member Author

byorgey commented Dec 30, 2021

Right, implementing this would probably require adding some features to svg-builder, I'm not sure. svg-tree doesn't really help. In the meantime, you might want to look into https://github.com/diagrams/diagrams-input , which has never been released to Hackage but should still work. It has a way to convert an SVG into a diagrams path, I think, which might be overkill depending on your use case but it's better than nothing.

@igormoreno
Copy link
Contributor

Thank you so much! I've been using that. It's exactly what I needed. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants