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 ¶
- func GenerateThumbnailAndHashes(file *os.File) (*bytes.Buffer, *sql.NullString, *sql.NullInt64, error)
- func GetBytesBuffer() *bytes.Buffer
- func GetImagePhash64() *imagehash.PHash64
- func GetMD5() hash.Hash
- func GetNullInt64() *sql.NullInt64
- func GetNullString() *sql.NullString
- func PutBytesBuffer(buf *bytes.Buffer)
- func PutImagePhash64(phash64 *imagehash.PHash64)
- func PutMD5(h hash.Hash)
- func PutNullInt64(ni *sql.NullInt64)
- func PutNullString(ns *sql.NullString)
- type Generator
- type MockGenerator
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 ¶
GetBytesBuffer retrieves a bytes.Buffer from the pool.
func GetImagePhash64 ¶
GetImagePhash64 retrieves an imagehash.PHash64 from the pool.
func GetNullInt64 ¶
GetNullInt64 retrieves an sql.NullInt64 from the pool.
func GetNullString ¶
func GetNullString() *sql.NullString
GetNullString retrieves an sql.NullString from the pool.
func PutBytesBuffer ¶
PutBytesBuffer returns a bytes.Buffer to the pool, resetting it first.
func PutImagePhash64 ¶
PutImagePhash64 returns an imagehash.PHash64 to the pool, resetting it first.
func PutNullInt64 ¶
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.