badge

package
v0.0.0-...-40c38fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package badge provides an easy way to create SVG badges.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Maker

type Maker struct {
	// contains filtered or unexported fields
}

A Maker knows how to make badges.

Example
package main

import (
	"fmt"
	"log"

	"github.com/campoy/svg-badge/badge"
	"golang.org/x/image/font/gofont/goregular"
)

func main() {
	m, err := badge.NewMaker("Go Regular", goregular.TTF)
	if err != nil {
		log.Fatal(err)
	}

	b, err := m.New("awesome", "sauce", "fab", 12, 25)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", b)
}
Output:

<?xml version="1.0"?>
<!-- Generated by SVGo -->
<svg width="117" height="25"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
<style type="text/css">
<![CDATA[
text { font-family: Go Regular,Verdana,Geneva,sans-serif; font-size: 12px; fill: white; }
]]>
</style>
<linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="#000" stop-opacity="0.00"/>
<stop offset="100%" stop-color="#000" stop-opacity="0.25"/>
<stop offset="100%" stop-color="#000" stop-opacity="1.00"/>
</linearGradient>
<rect x="0" y="0" width="117" height="25" rx="5" ry="5" style="fill:#666"/>
<rect x="68" y="0" width="49" height="25" rx="5" ry="5" style="fill:#fab"/>
<rect x="68" y="0" width="5" height="25" style="fill:#fab"/>
<rect x="0" y="0" width="117" height="25" rx="5" ry="5" style="fill:url(#gradient)"/>
<text x="8" y="15" >awesome</text>
<text x="76" y="15" >sauce</text>
</svg>

func NewMaker

func NewMaker(fontName string, fontData []byte) (*Maker, error)

NewMaker returns a new Maker given the font it should use.

func (*Maker) New

func (m *Maker) New(left, right, color string, fontSize float64, height int) ([]byte, error)

New creates a new badge given the wished text, color, font size, and height.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL