-
Notifications
You must be signed in to change notification settings - Fork 12
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 SVG badges as well as PNG #234
Comments
As I understand it, we can likely use django templates to create editable parts of an SVG file to drop in urls, organisation names and so on. From there, if we want to expose the SVG directly for resolution independent icons, we can and there are a number of libraries that can convert from SVG to PNG or other formats. Some examples below for conversion from svg to png, etc. https://stacktuts.com/how-to-convert-svg-to-png-or-jpeg-in-python |
This has been the subject of much team discussion of late, mainly as we have been working on rebranding the badges. It's likely they will end up looking something like this when deployed: The badges for now remain in .png format, as there is no straightforward way to output them as a .svg within our current Django set-up. However, we are keen to press forward with a more modern approach that can yield sharper graphics and a smaller file size eg an .svg version as this card describes. We know the .png format is not ideal. The current suggestion is to explore creating a web component like . More info on web components here: https://developer.mozilla.org/en-US/docs/Web/API/Web_components This card is tagged 'help needed' and we remain open to having some open source contributions to help us speed this along. Or some donations so we can hire in some help. For now it's nearing the top of the backlog, and I'd like to think w'd get to this in Q2/Q3 of this year 🤞 |
Also want to add some feedback we've received from the recent deployment of our new badges that offering some different colour options might be good as our green is quite opinionted. For example a greyscale version. Think again the web component option might help with making this possible. |
Hello there. I stumbled upon this thread while trying to get an SVG version of the greencheck badge for a community website I'm building. Below is my finding. Alternative Solution - Cloudflare WorkerI built a Cloudflare worker that basically does what
I see that I explained more in the next section why I ended up with this solution instead of one in Python. For now, some caveats:
Possibility with PythonI spent some time researching if it's possible to do this in Python as that would be best given the current setup. I'm sure it is possible for someone having deep enough experience with Python. For me, unfortunately, the current constraints make it virtually impossible to do so, namely: the image uses a custom font "TWK Everett", which requires installing into the deployed environment or loading dynamically at runtime, which is not supported by most popular tools for handling svg. Once we can figure that out, the remaining work is to find a tool that can take the loaded font, generate a path from an SVG text element and inject that into a prebuilt template. Important If business can allow the dynamic text (user-input url and hosting provider) to be in a universally-available font, however, I think using Python is more practical. Will find some more time to spend on this but not sure if it leads anywhere. Web component@hanopcan mentioned web component, but i am not sure what she has in mind exactly. Perhaps that means building an HTML custom element such as the following? <script src="https://unpkg.com/...path-to-custom-element-script"></script>
<green-check-image url="thegreenwebfoundation.org"></green-check-image> I'm not totally against this idea, but not sure if it's really necessary either. Web component requires Javascript on the browser and cannot be server-side-rendered. Taking into account everything, i believe it uses more resources than an image would - not the greenest it can be, to put simply. That being said, I can help with creating a web component if that ends up being the chosen solution. |
@vnphanquang thanks for your very detailed input for this issue. It's really cool to see how you've used edge workers to make this possible. What you've outlined there should be feasible to implement (i.e. creating a worker at a given path & then routing all greencheck badge requests through that path). However, it would create an extra bit of complexity around how the greencheck badges are delivered, and would be something extra we'd need to keep track of and manage. Doable for sure, but let me explain some of the thinking behind a web component, which we think would be a good way forwards. Web componentYes, the idea would be a custom HTML element. We'd look to keep the script for this as small as possible & would make it available to self-host as well. The element itself could be progressively enhanced.
An upside to using a web component would be that we can open up parts of the badge to be styled by those who are using it. That's a very common request we get from our users & one we'd really like to make possible. It would also give us the potential to create a "dark mode" version of the badge which would be a nice little addition to the default. |
@fershad thanks for the input. I understand. If you've worked with web component before, I think you'll agree that progressive enhancement and customization are generally difficult when it comes to web component. That being said, this is a "simple enough" use case and I think it's worth a try. I've put together a web component library at https://github.com/vnphanquang/green-check. Please take a look and feel free to give feedback / open issue. I'm happy to transfer the repo over to You can give it a try by parsing below example into codepen or any applicable playground: <script type="importmap">
{
"imports": {
"@vnphanquang/green-check": "https://cdn.jsdelivr.net/npm/@vnphanquang/green-check/dist/index.js"
}
}
</script>
<script type="module">
import { GreenCheck } from '@vnphanquang/green-check';
// later where applicable
customElements.define('green-check', GreenCheck);
</script>
<green-check hostname="github.com"></green-check>
<green-check hostname="google.com"></green-check>
<green-check></green-check> More info can be seen in the repo README. A couple quick things:
Thanks a lot team. |
Oh wow @vnphanquang, that's brilliant!! Thanks so much for putting the repo together. |
Echoing @fershad here @vnphanquang - we are so incredibly grateful for the time and effort you've put in here, thank you! 💚 I'm just returning from a week of leave so let me give this some proper thought next week and have a discussion with Fershad about what we do next. |
@vnphanquang thanks for creating that web component. I had a play with it in Codepen and it was really easy to use and customise. Very cool. We've flagged this internally as something we'd like to pick up again in October once a few of us a back from holidays. |
@vnphanquang, sorry that it's taken so long to get back you about this. We'd love for this web component to be something we can put alongside the image version of the badge in Green Web Check results. For that to happen, we'd need to bring this code into a repository under our own organisation account in some way. That allows us to provide a consistent contributor experience across all our repos, with a Code of Conduct, approach for managing issues, links to sponsor green web fdn work, and so on. It also includes control over roadmap, and new releases ( deploying to npm, security fixes, etc). We'd like to know how you'd like us to do that. We could either
|
@fershad no worries at all. Glad you have been finding the component useful. I'm happy with either direction you proposed. Please feel free to go with whichever more convenient for your team. I'm also happy to let you take complete ownership of the project, but if you need my help with anything I'm always available. I've been wanting to implement some basic sanity tests but haven't found the time. In any case please let me know and I'll initiate a transfer. From my side after you've successfully publish a new package in NPM, I'll need to do a patch update to deprecate my current one and point it to the new repo/package. If it's more convenient for you, my DM is open on almost all social media at |
We have an API end point for serving images, that looks like like the link below:
https://api.thegreenwebfoundation.org/greencheckimage/thegreenwebfoundation.org
This serves a PNG file so you can add it as a src tag:
There is caching involved, but this an image generated using data from our database.
We've had someone folks request an SVG version of this as well, and this would be nice to add, as if we have a sample SVG we could render the same information into it, probably resulting in smaller file size too.
This would involve creating an SVG largely along the same lines as these blank template versions we currently use for creating bitmap images
https://github.com/thegreenwebfoundation/admin-portal/tree/master/apps/greencheck/badges
Implementing this
We don't really have the in- house experience to create an SVG file for this, but we would gladly accept pull requests that make it possible for people to request it, so for requests that look like the one below, we could serve the SVG file:
https://api.thegreenwebfoundation.org/greencheckimage/thegreenwebfoundation.org?type=svg
The text was updated successfully, but these errors were encountered: