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

Support importing a svg into the SVG object #57

Open
hhhapz opened this issue Jul 4, 2021 · 4 comments · May be fixed by #58
Open

Support importing a svg into the SVG object #57

hhhapz opened this issue Jul 4, 2021 · 4 comments · May be fixed by #58

Comments

@hhhapz
Copy link

hhhapz commented Jul 4, 2021

Would be really cool if we could get functionality that allowed us to take an already existing svg (a file, for example) and import it into svgo and modify it!

This would be really helpful when working with large preexisting svgs and adding dynamic content on top of it :)

Here how I envision it to be used:

buf, err := os.OpenFile("my.svg")
if err != nil {
  return err
}
canvas, err := svg.Import(buf, os.Stdout)
if err != nil {
  return err
}
canvas.DoAwesomeThings(...)
// ...
canvas.End() // my.svg with awesome things done to it printed to stdout
@hhhapz
Copy link
Author

hhhapz commented Jul 4, 2021

I suppose this could be achieved two fold, by writing a partial svg to the writer before using svgo, or embedding the svg, especially as the target for this library is generation specifically. Curious to know what your thoughts are on this, and if it's out of scope, feel free to close the issue :). Thanks for the great lib 😀

@ajstarks
Copy link
Owner

ajstarks commented Jul 4, 2021

See: https://github.com/ajstarks/svgo/blob/master/codepic/codepic.go for an approach to this.

@hhhapz
Copy link
Author

hhhapz commented Jul 4, 2021

Hey @ajstarks the placepic solution is really elegant! Thanks for writing it. Would you be open if I opened a PR that is a bit more simplified version of it that focuses more on embedding an svg within another? Perhaps under the name embed.go. Let me know if you are cool with that :)

@ajstarks
Copy link
Owner

ajstarks commented Jul 4, 2021

sure, I'm ok with reviewing embed.go.

hhhapz added a commit to hhhapz/svgo that referenced this issue Jul 5, 2021
This commit adds the embed.go example, which focuses on demonstrating
how to embed an svg within another. The example adds a title and a red
border around the svg file provided via the -f argument.

Closes ajstarks#57.
@hhhapz hhhapz linked a pull request Jul 5, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants