ppic

package module
v0.0.0-...-a244deb Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: AGPL-3.0 Imports: 18 Imported by: 0

README

go-ppic

Profile picture generation service written in Go. A demo can be found at go-ppic.herokuapp.com.

go-ppic provides two commands; ppicd and ppic.

ppicd

ppicd is a web server providing image generation.

Installation
go get -u github.com/jackwilsdon/go-ppic/cmd/ppicd
Usage
  -d	enable pprof debug routes
  -h string
    	host to run the server on
  -p uint
    	port to run the server on (default 3000)
  -v	enable verbose output
  -z	enable gzip compression

After starting up the server, you should see something similar to the following output;

2006/01/02 15:04:05 starting server on http://127.0.0.1:3000...

Visiting the URL that the server is running on will give you the image for an empty string. You can get the image for the string "example" by visiting /example on the server (http://127.0.0.1:3000/example in this case).

URL Parameters

The server accepts the following query parameters to change the response;

  • ?size=N → specify the size of the image to return (must be a multiple of 8)
  • ?monochrome → change the image to black and white
Supported Extensions

By default the server will respond in PNG format, but it also supports the following file extensions;

  • .gif
  • .jpeg

ppic

ppic is used to generate profile pictures on the command line, without having to run a web server. ppic outputs the generated image to stdout.

Installation
go get -u github.com/jackwilsdon/go-ppic/cmd/ppic
Usage
usage: ppic text [size] > image.png

size defaults to 512 if not provided

Examples
ppic jackwilsdon 1024 > profile.png

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPalette = Palette{Foreground: color.Black, Background: color.White}

DefaultPalette is the default black and white color palette.

View Source
var ErrInvalidSize = errors.New("size must be a multiple of 8")

ErrInvalidSize is an error caused by specifying a size which is not a multiple of 8.

Functions

func Generate

func Generate(k string, mX, mY bool) (img [8][8]bool)

Generate returns an 8x8 grid of values based on the provided source text, optionally mirrored along the X or Y axis.

func GenerateImage

func GenerateImage(grid [8][8]bool, size int, p Palette) (image.Image, error)

GenerateImage returns an image for the specified grid.

func Handler

func Handler(res http.ResponseWriter, req *http.Request)

Handler serves HTTP requests with generated images.

Types

type Palette

type Palette struct {
	Foreground color.Color
	Background color.Color
}

Palette represents a pair of colors to use in image generation.

func GeneratePalette

func GeneratePalette(k string) Palette

GeneratePalette generates a color palette from a string.

func (Palette) Palette

func (p Palette) Palette() color.Palette

Palette returns a color palette with the first color being the background and the second being the foreground.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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