Skip to content

Build and types

libphash_version

libphash_version() -> str

Return the version of the bundled libphash ("2.0.2").

It is the first three numbers of __version__.

build_info

build_info() -> str

Return how the bundled libphash was built.

The string lists the version, decoders, threads and SIMD: "version=2.0.2 jpeg=libjpeg-turbo png=libpng ...".

can_decode

can_decode(fmt: Literal['jpeg', 'png', 'webp']) -> bool

Return whether this build has a native decoder for the format.

JPEG and PNG decode without one too (through stb_image); WebP does not.

digest_info

digest_info(algorithm: AlgorithmLike, config: Config | None = None) -> tuple[int, DigestKind]

Return the size in bytes and the kind of the hashes algorithm produces.

No image is needed: the answer depends only on config, which makes it fit for sizing a database column, say. A 64-bit hash is 8 BITS bytes.

Types

Source module-attribute

Source = Union[str, 'os.PathLike[str]', 'os.PathLike[bytes]', bytes, bytearray, memoryview, SupportsArrayInterface, SupportsRead]

Everything :func:libphash.hash and :meth:ImageContext.load accept: a path, encoded bytes, a binary file object, an array of pixels or a Pillow image. bytes are always encoded image data, never a path.

StrPath module-attribute

StrPath = Union[str, bytes, 'os.PathLike[str]', 'os.PathLike[bytes]']

A file system path, as open() takes it.

PixelArray module-attribute

PixelArray = SupportsArrayInterface | memoryview

Decoded 8-bit pixels of shape (h, w) or (h, w, 1|3|4): a numpy array, a memoryview.

AlgorithmLike module-attribute

AlgorithmLike = Union['Algorithm', str]

ChannelOrder module-attribute

ChannelOrder = Literal['rgb', 'bgr']

Order of the color channels in an array of pixels: "bgr" is OpenCV's.

AlphaMode module-attribute

AlphaMode = Literal['grey', 'white', 'black', 'ignore']

WHashMode module-attribute

WHashMode = Literal['fast', 'full']

DecodeScale module-attribute

DecodeScale = Literal[1, 2, 4, 8]

SupportsRead

Bases: Protocol

A binary file object: an open file, io.BytesIO, a response body.

SupportsArrayInterface

Bases: Protocol

An array exposing numpy's __array_interface__.

A numpy array is one, and so is a Pillow image.

PILImage

Bases: Protocol

The part of PIL.Image.Image the binding reads.