imagetemplate

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 10 Imported by: 0

README

Image Template

GoDoc Build Status Coverage Status Go Report Card Maintainability

An image templating library for golang. Builder provides the templating engine, render provides the canvas, individual components provide the elements which can be templated and rendered. Component registration follows the pattern of built-in package "image", any package which implements the Component interface (found under render) and uses the RegisterComponent function during initialisation will be available for use.

Several default components are included, see their documentation as well as detailed usage guidelines for the template files and Builder in the documentation pages.

Installation

go get "github.com/LLKennedy/imagetemplate/v3"

Basic Usage

loader, props, err := imagetemplate.New().Load().FromFile("template.json")

// Check props here, set any discovered variables with real values.

data, err := loader.Write().ToBMP(props)
err = ioutil.WriteFile("output.bmp", data, os.ModeExclusive)

Testing

On windows, the simplest way to test is to use the powershell script.

./test.ps1

To emulate the testing which occurs in build pipelines for linux and mac, run the following:

go test ./... -race

Documentation

Overview

Package imagetemplate generates images from JSON templates and application-specific variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadOptions

type LoadOptions interface {
	FromBuilder(builder scaffold.Builder) (Loader, render.NamedProperties, error)
	FromBytes(bytes []byte) (Loader, render.NamedProperties, error)
	FromFile(path string) (Loader, render.NamedProperties, error)
	FromJSON(raw json.RawMessage) (Loader, render.NamedProperties, error)
	FromReader(reader io.Reader) (Loader, render.NamedProperties, error)
}

LoadOptions chooses the input format for Loader.

type Loader

type Loader interface {
	Load() LoadOptions
	Write() WriteOptions
}

Loader creates image builders from several input options and writes the finished product to several output formats.

func New

func New() Loader

New returns a new loader with the default file system.

func NewUsing

func NewUsing(fs vfs.FileSystem) Loader

NewUsing returns a new loader using a specified vfs.

type WriteOptions

type WriteOptions interface {
	ToBuilder(props render.NamedProperties) (scaffold.Builder, error)
	ToBMP(props render.NamedProperties) ([]byte, error)
	ToCanvas(props render.NamedProperties) (render.Canvas, error)
	ToImage(props render.NamedProperties) (image.Image, error)
	ToBMPReader(props render.NamedProperties) (io.Reader, error)
}

WriteOptions chooses the output format for Loader.

Directories

Path Synopsis
components
barcode
Package barcode is a component for rendering barcodes with customisable content and colour for both background and data channels.
Package barcode is a component for rendering barcodes with customisable content and colour for both background and data channels.
circle
Package circle is a simple circle component with customisable size, colour, location and radius.
Package circle is a simple circle component with customisable size, colour, location and radius.
datetime
Package datetime is a text-based time component with customisable content, size, colour, location and time format.
Package datetime is a text-based time component with customisable content, size, colour, location and time format.
image
Package image is an embedded image component with support for jpg, png, bmp and tiff files.
Package image is an embedded image component with support for jpg, png, bmp and tiff files.
rectangle
Package rectangle is a simple rectangle component with customisable size, colour and location.
Package rectangle is a simple rectangle component with customisable size, colour and location.
text
Package text is a simple text component with customisable content, size, colour, location and font.
Package text is a simple text component with customisable content, size, colour, location and font.
Package cutils provides common parsing/conversion code for components to cut down on duplication
Package cutils provides common parsing/conversion code for components to cut down on duplication
internal
filesystem
Package filesystem is a mock filesystem.
Package filesystem is a mock filesystem.
Package render renders images onto a canvas.
Package render renders images onto a canvas.
Package scaffold parses JSON data, matches it to known template components and controls rendering of the resultant image.
Package scaffold parses JSON data, matches it to known template components and controls rendering of the resultant image.

Jump to

Keyboard shortcuts

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