thumbnail

package
v0.1.149 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package thumbnail provides functionality for generating image thumbnails and computing image hashes (MD5, pHash). It uses lightweight pooling for buffers and hashers to minimize allocations and improve performance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateThumbnailAndHashes

func GenerateThumbnailAndHashes(file *os.File) (*bytes.Buffer, *sql.NullString, *sql.NullInt64, error)

GenerateThumbnailAndHashes creates a thumbnail for the image at the given file. It resizes the image to fit within a 200x150 pixel box while maintaining aspect ratio, and encodes the resulting thumbnail as a JPEG. It also calculates MD5 and pHash. It returns the JPEG data as a bytes.Buffer, and sql.NullString for MD5, and sql.NullInt64 for pHash, or an error if generation fails.

func GetBytesBuffer

func GetBytesBuffer() *bytes.Buffer

GetBytesBuffer retrieves a bytes.Buffer from the pool.

func GetImagePhash64

func GetImagePhash64() *imagehash.PHash64

GetImagePhash64 retrieves an imagehash.PHash64 from the pool.

func GetMD5

func GetMD5() hash.Hash

GetMD5 retrieves an MD5 hash.Hash from the pool.

func GetNullInt64

func GetNullInt64() *sql.NullInt64

GetNullInt64 retrieves an sql.NullInt64 from the pool.

func GetNullString

func GetNullString() *sql.NullString

GetNullString retrieves an sql.NullString from the pool.

func PutBytesBuffer

func PutBytesBuffer(buf *bytes.Buffer)

PutBytesBuffer returns a bytes.Buffer to the pool, resetting it first.

func PutImagePhash64

func PutImagePhash64(phash64 *imagehash.PHash64)

PutImagePhash64 returns an imagehash.PHash64 to the pool, resetting it first.

func PutMD5

func PutMD5(h hash.Hash)

PutMD5 returns an MD5 hash.Hash to the pool, resetting it first.

func PutNullInt64

func PutNullInt64(ni *sql.NullInt64)

PutNullInt64 returns an sql.NullInt64 to the pool, resetting it first.

func PutNullString

func PutNullString(ns *sql.NullString)

PutNullString returns an sql.NullString to the pool, resetting it first.

Types

type Generator

type Generator interface {
	// GenerateThumbnailAndHashes creates a thumbnail and computes MD5/pHash.
	// The reader should be an image file.
	// Returns thumbnail bytes, MD5 hash, perceptual hash, and any error.
	GenerateThumbnailAndHashes(r io.ReadSeeker) (*bytes.Buffer, *sql.NullString, *sql.NullInt64, error)
}

Generator abstracts thumbnail generation and hash computation.

type MockGenerator

type MockGenerator struct {
	Thumbnail *bytes.Buffer
	MD5       *sql.NullString
	PHash     *sql.NullInt64
	Err       error
}

MockGenerator is a mock implementation of Generator for testing.

func (*MockGenerator) GenerateThumbnailAndHashes

func (m *MockGenerator) GenerateThumbnailAndHashes(r io.ReadSeeker) (*bytes.Buffer, *sql.NullString, *sql.NullInt64, error)

GenerateThumbnailAndHashes returns the mock values.

Jump to

Keyboard shortcuts

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