blockhash

package module
v0.0.0-...-e3fd744 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2016 License: MIT Imports: 7 Imported by: 0

README

blockhash-go

Build Status GoDoc

Go implementation of blockhash, a perceptual hash of images

See godoc.org for documentation.

Reference implementation

Install

go get "github.com/haochi/blockhash-go"

Test Images

Test images are in public domain and I found them on https://pixabay.com

Documentation

Overview

Go implementation of blockhash (http://blockhash.io), a perceptual hash of images

Reference implementation: https://github.com/commonsmachinery/blockhash-python/tree/0d76144cf5b6ac149ff7612ab433a48b0fb9139b

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash struct {
	// bit representation of the hash
	Bits []int
}

func Blockhash

func Blockhash(reader io.Reader, bits int) (*Hash, error)

Generates the block hash for a given image `bits` should be a power of 2 number (e.g. 2, 4, 8, 16, etc.); the number of output bits is equal to bits^2

Example
reader, err := os.Open(defaultFile) // Get the file reader for the image
if err != nil {
	log.Fatal(err)
}
hash, _ := Blockhash(reader, 16)    // Divide the image into 16x16 blocks, and calculate the hash
fmt.Println("Bits", hash.Bits[:32]) // You should use the entire content in `Bits` though
fmt.Println("Hex", hash.ToHex())
Output:

Bits [1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0]
Hex 801e3818fd80ffecfffc0ffc0e38000899ff193c1d38083c5c6c9e781e310fb0

func (*Hash) ToHex

func (hash *Hash) ToHex() string

A string representation of the hash in hex format

Jump to

Keyboard shortcuts

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