zplgfa

package module
v1.0.5 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 Build Status Coverage Status Go Report Card codebeat badge BCH compliance FOSSA Status 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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressASCII added in v1.0.3

func CompressASCII(in string) string

CompressASCII compresses the ASCII data of a ZPL Graphic Field using RLE

Example
package main

import (
	"fmt"
	"simonwaldherr.de/go/zplgfa"
)

func main() {
	str := zplgfa.CompressASCII("FFFFFFFF000000")
	fmt.Print(str)

}
Output:

NFL0

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 chosen 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 well as a Field Separator and Field Origin.

func FlattenImage

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

FlattenImage optimizes an image for the converting process

Types

type GraphicType

type GraphicType int

GraphicType is a type to select the graphic format

const (
	// ASCII graphic type using only hex characters (0-9A-F)
	ASCII GraphicType = iota
	// Binary saving the same data as binary
	Binary
	// CompressedASCII compresses the hex data via RLE
	CompressedASCII
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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