imagetemplate

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 22 Imported by: 0

README

Image Template

This project defines a template file for drawing custom images from pre-defined components. The intended application is smartcard printing, and some assumptions may be made with that in mind, but this format should be appropriate for general use.

GoDoc Build Status Coverage Status Go Report Card

Testing

go test . -covermode=count -coverprofile="coverage.out"; go tool cover -html="coverage.out"

Documentation

Overview

Package imagetemplate defines a template for drawing custom images from pre-defined components, and provides to tools to load and implement that template.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseColour

type BaseColour struct {
	Red   string `json:"R"`
	Green string `json:"G"`
	Blue  string `json:"B"`
	Alpha string `json:"A"`
}

BaseColour is the template format of the base colour settings

type BaseImage

type BaseImage struct {
	FileName   string     `json:"fileName"`
	Data       string     `json:"data"`
	BaseColour BaseColour `json:"baseColour"`
	BaseWidth  string     `json:"width"`
	BaseHeight string     `json:"height"`
}

BaseImage is the template format of the base image settings

type Builder

type Builder interface {
	GetCanvas() render.Canvas
	SetCanvas(newCanvas render.Canvas) Builder
	GetComponents() []render.Component
	SetComponents(components []ToggleableComponent) Builder
	GetNamedPropertiesList() render.NamedProperties
	SetNamedProperties(properties render.NamedProperties) (Builder, error)
	ApplyComponents() (Builder, error)
	LoadComponentsFile(fileName string) (Builder, error)
	LoadComponentsData(fileData []byte) (Builder, error)
	WriteToBMP() ([]byte, error)
}

Builder manipulates Canvas objects and outputs to a bitmap

func LoadTemplate

func LoadTemplate(path string) (Builder, error)

LoadTemplate takes a file path and returns a Builder constructed from the template file

type ComponentTemplate

type ComponentTemplate struct {
	Type        string                      `json:"type"`
	Conditional render.ComponentConditional `json:"conditional"`
	Properties  json.RawMessage             `json:"properties"`
}

ComponentTemplate is a partial unmarshalled Component, with its properties left in raw form to be handled by each known type of Component.

type ImageBuilder

type ImageBuilder struct {
	Canvas          render.Canvas
	Components      []ToggleableComponent
	NamedProperties render.NamedProperties
	// contains filtered or unexported fields
}

ImageBuilder uses golang's native Image package to implement the Builder interface

func NewBuilder

func NewBuilder() ImageBuilder

NewBuilder generates a new ImageBuilder with an internal canvas of the specified width and height, and optionally the specified starting colour. No provided colour will result in defaults for Image.

func (ImageBuilder) ApplyComponents

func (builder ImageBuilder) ApplyComponents() (Builder, error)

ApplyComponents iterates over the internal Component array, applying each in turn to the Canvas

func (ImageBuilder) GetCanvas

func (builder ImageBuilder) GetCanvas() render.Canvas

GetCanvas returns the internal Canvas object

func (ImageBuilder) GetComponents

func (builder ImageBuilder) GetComponents() []render.Component

GetComponents gets the internal Component array

func (ImageBuilder) GetNamedPropertiesList

func (builder ImageBuilder) GetNamedPropertiesList() render.NamedProperties

GetNamedPropertiesList returns the list of named properties in the builder object

func (ImageBuilder) LoadComponentsData

func (builder ImageBuilder) LoadComponentsData(fileData []byte) (Builder, error)

LoadComponentsData sets the internal component array based on the contents of the specified JSON data

func (ImageBuilder) LoadComponentsFile

func (builder ImageBuilder) LoadComponentsFile(fileName string) (Builder, error)

LoadComponentsFile sets the internal Component array based on the contents of the specified JSON file

func (ImageBuilder) SetCanvas

func (builder ImageBuilder) SetCanvas(newCanvas render.Canvas) Builder

SetCanvas sets the internal Canvas object

func (ImageBuilder) SetComponents

func (builder ImageBuilder) SetComponents(components []ToggleableComponent) Builder

SetComponents sets the internal Component array

func (ImageBuilder) SetNamedProperties

func (builder ImageBuilder) SetNamedProperties(properties render.NamedProperties) (Builder, error)

SetNamedProperties sets the values of names properties in all components and conditionals in the builder

func (ImageBuilder) WriteToBMP

func (builder ImageBuilder) WriteToBMP() ([]byte, error)

WriteToBMP outputs the contents of the builder to a BMP byte array

type Template

type Template struct {
	BaseImage  BaseImage           `json:"baseImage"`
	Components []ComponentTemplate `json:"components"`
}

Template is the format of the JSON file used as a template for building images. See samples.json for examples, each element in the samples array is a complete and valid template object.

type ToggleableComponent

type ToggleableComponent struct {
	Conditional render.ComponentConditional
	Component   render.Component
}

ToggleableComponent is a component with its conditional

Directories

Path Synopsis
components
internal
demo command
filesystem
Package filesystem provides file system access
Package filesystem provides file system access
Package render renders images onto a canvas.
Package render renders images onto a canvas.

Jump to

Keyboard shortcuts

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