zplgfa

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: MIT Imports: 6 Imported by: 0

README

ZPLGFA Golang Package

GoDoc Go Report Card license

The ZPLGFA Golang package implements some functions to convert PNG, JPEG and GIF files to ZPL compatible ^GF-elements (Graphic Fields).

install

  1. install Golang
  2. go get simonwaldherr.de/go/zplgfa

example

package main

import (
    "simonwaldherr.de/go/zplgfa"
    "fmt"
    "image"
    _ "image/gif"
    _ "image/jpeg"
    _ "image/png"
    "log"
    "os"
)

func main() {
    // open file
    file, err := os.Open("label.png")
    if err != nil {
        log.Printf("Warning: could not open the file: %s\n", err)
        return
    }

    defer file.Close()

    // load image head information
    config, format, err := image.DecodeConfig(file)
    if err != nil {
        log.Printf("Warning: image not compatible, format: %s, config: %v, error: %s\n", format, config, err)
    }

    // reset file pointer to the beginning of the file
    file.Seek(0, 0)

    // load and decode image
    img, _, err := image.Decode(file)
    if err != nil {
        log.Printf("Warning: could not decode the file, %s\n", err)
        return
    }

    // flatten image
    flat := zplgfa.FlattenImage(img)

    // convert image to zpl compatible type
    gfimg := zplgfa.ConvertToZPL(flat, zplgfa.CompressedASCII)

    // output zpl with graphic field date to stdout
    fmt.Println(gfimg)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToGraphicField

func ConvertToGraphicField(source image.Image, graphicType GraphicType) string

ConvertToGraphicField converts an image.Image picture to a ZPL compatible Graphic Field. The ZPL ^GF (Graphic Field) supports various data formats, this package supports the normal ASCII encoded, as well as a RLE compressed ASCII format. It also supports the Binary Graphic Field format. The encoding can be choosen by the second argument.

func ConvertToZPL

func ConvertToZPL(img image.Image, graphicType GraphicType) string

ConvertToZPL is just a wrapper for ConvertToGraphicField which also includes the ZPL starting code ^XA and ending code ^XZ, as wall as a Field Separator and Field Origin.

func FlattenImage

func FlattenImage(source image.Image) *image.NRGBA

Types

type GraphicType

type GraphicType int
const (
	ASCII GraphicType = iota
	Binary
	CompressedASCII
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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