top | item 21463051

(no title)

bquinlan | 6 years ago

I created an equivalent project for people who wanted to create the same style of badges from Python (or from the command line): https://github.com/google/pybadges

Python example:

  from pybadges import badge
  s = badge(left_text='coverage',
            right_text='23%', 
           right_color='red')
  # s is a string that contains the badge data as an svg image.
  print(s[:40]) # => <svg height="20" width="191.0" xmlns="ht

Command line example:

  python -m pybadges \
    --left-text="coverage" \
    --right-text="23%" \
    --right-color="red"
But there are lots more formatting options documented on the project page.

discuss

order

olivierlacan|6 years ago

Hey, Shields creator here. One of the most important features of Shields since the very beginning was to offer a conventional usable and user-centered style to fight the vendor badge arms race between all the developer SaaS companies that were sprouting up around 2012/2013. See: https://olivierlacan.com/posts/an-open-source-rage-diamond/

Please consider contributing to Shields if you want to improve Python ecosystem support. We already support PyPI, Pipenv/GitHub, and a host of others. I'll gladly admit the interface for discovering badge types could use some improvement but the Shields community and maintainers have been working on that for a while.

We spent a lot of time designing, refining, adding support for hundreds of services and package managers, and offering a ridiculously simple to use API for everyone's metadata badge needs. So check out img.shields.io and see for yourself how you can already (lightly) customize badge styles to suit your taste.

https://img.shields.io/badge/contribute-please-red?style=fla...

Thanks :-)

cuu508|6 years ago

I went more minimalistic and added SVG badge support in the form of a Django template and a couple small python functions.

The template: https://raw.githubusercontent.com/healthchecks/healthchecks/...

And the function for rendering the template: https://github.com/healthchecks/healthchecks/blob/master/hc/...

One funky thing there is the measurement of text width. The width of the badge depends of the width of the text you put into it. I simply measured the width of each individual alphabet letter, and use that to calculate the width of a string. It's not super accurate, but works fine in practice. It was a fun weekend project.

bquinlan|6 years ago

Nice! My approach is very similar except that I have width mappings for non-ASCII characters. Also, since DejaVu Sans (the font that shield.io, pybadges and healthchecks use) is heavily kerned, I have a table of kerning widths.

You can also opt to use precise text width measurements (important for Arabic, Chinese, etc.) but then you have to have the font file available on your system.