API / Minn\Media / PhotoMeta

PhotoMeta final class

Minn\Media\PhotoMeta · public/minn/src/Minn/Media/PhotoMeta.php · 165 lines

A photo's own description, read as the reference's wp_read_image_metadata reads it (probe image-meta): IPTC first (headline or object name for the title, caption, credit or byline, copyright, keywords, the date and time it was made), then EXIF for what IPTC left empty (a short description as the title, the user comment or description as the caption, the artist, copyright, model, the digitized time, aperture, focal length, ISO, exposure, orientation). Text that is not UTF-8 is read as Latin-1, and every value is cleaned (the reference runs wp_kses_post) and made a string; a short caption doubles as the title.

Uses 1

Constants and properties

constEXIF_TYPES = array ( 0 => 2, 1 => 7, 2 => 8, )

EXIF is read for these image types only: JPEG and TIFF, both byte orders.

Public

staticread(string $file, array $exifTypes, Closure $clean): ?array#

The metadata, the image type, the IPTC and EXIF it came from; null when there is no such file.

$exifTypeslist<int>
$cleanClosure(string): string
@return array{meta: array<string, mixed>, type: int|null, iptc: array<string, mixed>, exif: array<string, mixed>}|null

Internals 6

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatefromIptc(array $meta, array $iptc): array#
$metaarray<string, mixed>
$iptcarray<string, mixed>
@return array<string, mixed>
privatefromExif(array $meta, array $exif): array#
$metaarray<string, mixed>
$exifarray<string, mixed>
@return array<string, mixed>
privatedescribed(array $meta, string $description, string $comment, string $comments): array#

The title and caption EXIF gives when IPTC left them empty: a short description is the title, and the user comment (else the description) the caption; a description that is not the title runs on into the comment; a comment alone is the caption; a short caption doubles as the title.

$metaarray<string, mixed>
@return array<string, mixed>
privatefraction(mixed $value): float#

"28/10" as 2.8; a zero denominator reads 0.

privateexifTime(string $time): string#

An EXIF time ("2024:05:06 07:08:09") as a Unix time read as UTC.

privatecleaned(array $meta, Closure $clean): array#

Text made UTF-8 (Latin-1 read as such) and cleaned, every value a string.

$metaarray<string, mixed>
$cleanClosure(string): string
@return array<string, mixed>