tunabay / go-bmppath

A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Reference MIT License

go-bmppath

Overview

Package bmppath converts a monochrome 1-bit bitmap image into a set of vector paths.

Note that this package is by no means a sophisticated tool for tracing raster images in detail. It only has the ability to create vector paths with as few paths as possible. The vector paths created keep the shape of the square pixels and look jagged.

Originally this code was written for the purpose of converting a QR Code to a print format.

Examples

source bitmap paths

Note: I draw these images manually to give an overview. Therefore, the details may be slightly different from the actual paths output by the code. It's a known mistake that multiple arrows are drawn on one path :-)

Usage

import (
	"os"

	"github.com/tunabay/go-bitarray"
	"github.com/tunabay/go-bmppath"
)

func main() {
	bmp := bitarray.NewBufferFromByteSlice([]byte{
		0b_10000001,
		0b_01000010,
		0b_00111100,
		0b_01111110,
		0b_11011011,
		0b_01111110,
		0b_00100100,
		0b_11000011,
	})

	path, err := bmppath.New(bmp, 8)
	if err != nil {
		panic(err)
	}

	_ = path.WriteSVG(os.Stdout)
}

Run in Go Playground

Documentation

License

go-bmppath is available under the MIT license. See the LICENSE file for more information.

About

A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.

License:MIT License


Languages

Language:Go 100.0%