-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add support for Image widget to handle a file URL or SVG #504
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! Thanks so much for the change! It appears there are two main features in this change:
- Image by URL
- SVG support
Image by URL is not something we can support at this time. We can support SVGs (and love the feature!), though we'd like to figure out the performance of SVGs before we do just to ensure we don't become dependent on a library that we cant support.
|
||
// register image formats | ||
_ "image/jpeg" | ||
_ "image/png" | ||
|
||
"github.com/nfnt/resize" | ||
"github.com/srwiley/oksvg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for selecting this library? A quick search for golang svg
provides github.com/ajstarks/svgo
which appears to be much more popular, though I don't know the tradeoffs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason for selecting this library! Full disclosure, I am somewhat new to the Go community so I just kinda googled and picked one.
I'll take a look at the library you suggested and circle back with tradeoffs between the two so we can discuss! (Although for other languages I tend to lean whichever has more community support/actively maintained so the one you linked might be the winner).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright so I found some more info about these packages:
github.com/ajstarks/svgo
- Only supports SVG Spec 1.1
- Does not include a rasterizer for converting from SVG -> Image out of the box. I found this GitHub issue where the maintainer recommended inkscape cli or a java tool which i doubt you all want to include as a dependency to pixlet
github.com/srwiley/oksvg
- Supports SVG Spec 2.0 which is backwards compatible with SVG 1.1
- It appears this library was built with rasterizing in mind given they wrote the rasterizer I am using `srwiley/rasterx
I'm assuming that writing a svg rasterizer is out of scope for pixlet (though I can try to take a stab at it if it's something you want!) But with that in mind in my opinion the library i'm currently using (srwiley/oksvg
, srwiley/rasterx
) seems like a little bit better fit.
Lmk what you think!
@@ -147,12 +159,66 @@ func (p *Image) InitFromImage(data []byte) error { | |||
return nil | |||
} | |||
|
|||
func (p *Image) Init() error { | |||
err := p.InitFromWebP([]byte(p.Src)) | |||
func (p *Image) InitFromSVG(data []byte) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add a bench mark test here. I'm tempted to say we don't need it, but we risk some performance issues down the road that are hard to spot as I suspect SVGs can be rather expensive to rasterize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally, great callout!
Do you mind sharing some insight on what a reasonable upper bound of that benchmark should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't currently. I'd probably run a go bench
test on this method for all three image types and compare the results. I don't really have a strong sense of what reasonable would be. If it's twice as slow, that probably wouldn't be ok? But if SVGs are slightly slower, that's probably fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sorry that this has been left open for so long. I am going to merge this, but will follow up with removing the InitFromURL method given it's unused. We also may have to remove this functionality if it becomes a performance issue.
✅ Deploy Preview for pixlet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@betterengineering ah no problem at all! Thank you for merging! And totally understand if it needs to be removed because of performance issues, lmk if I can help with that if it comes up! |
Any update on SVG support? render.Image(src="https://media.kanjialive.com/kanji_strokes/ike_1.svg") |
Hi tidbyt team!
I just got a tidbyt as a gift and I am absolutely loving how configurable it is and that a developer experience has been beautifully built out!
When I was playing around with writing my first app, I really wanted the ability to support SVG's. As I was writing that piece in my own app code I realized that this library could easily support that out of the box and further I added the ability to do URL as well so
pixlet
could be even easier than it already is at onboarding developers.Hopefully it was ok that I opened this without being attached to an issue, I was trying to find Contributor guidelines but couldn't find much (please let me know if I missed something)
If there's any changes to syntax/style/etc please let me know, happy to change!
SVG +URL Example: