API / Minn\Media / Sizing

Sizing final class

Minn\Media\Sizing · public/minn/src/Minn/Media/Sizing.php · 263 lines

The image size arithmetic the media functions share: the crop or scale a resize needs, the registered size a requested box picks, and the srcset candidates an image's sizes yield. Behaviour pinned by contracts/fixtures/api/media.json.

Public

staticconstrain(int $width, int $height, int $maxWidth, int $maxHeight): array#

The largest box inside the limits that keeps the ratio: only sides over their limit shrink, the smaller ratio wins, and a result one pixel short of a limit it was constrained by snaps to that limit.

@return array{0: int, 1: int}
staticresize(int $origW, int $origH, int $destW, int $destH, bool $crop, Closure $constrain): ?array#

The GD-style resize box (dst x, dst y, src x, src y, dst w, dst h, src w, src h), or null when every asked dimension is larger than the image (nothing to make).

$constrainClosure(int, int, int, int): array{0: int, 1: int}scales a box into a maximum
@return array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int}|null
staticsameSize(array $box, int $origW, int $origH): bool#

Whether a resize box makes the image's own size again, a pixel either way counting as rounding.

$boxarray{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int}
staticintermediate(array $meta, array|string $size, ?string $fileUrl, Closure $editorConstrain, Closure $matchesRatio): ?array#

The registered size that serves a request: by name, or for a requested box the size of exactly that box, else the smallest larger one in its proportion (the full size never counts), else the thumbnail when it is wide enough; with its path and URL beside the file's.

$metaarray<string, mixed>attachment metadata
$sizestring|array{0: int, 1: int}
$editorConstrainClosure(int, int, array): array{0: int, 1: int}
$matchesRatioClosure(int, int, int, int): bool
@return array<string, mixed>|null
staticsources(array $sizeArray, string $src, array $meta, Closure $matchesRatio, string $uploadsUrl, Closure $maxWidth): array#

The srcset candidates by width: every size on the image's ratio (and the same edit, when the file was edited) no wider than the cap, the source itself winning a width clash and passing the cap.

$sizeArrayarray{0: int, 1: int}
$matchesRatioClosure(int, int, int, int): bool
$maxWidthClosure(array{0: int, 1: int}): intthe widest candidate (max_srcset_image_width; 0 for no cap), asked before the folder is checked
@return array<int, array{url: string, descriptor: string, value: int}>
staticsrcset(array $sources): ?string#

The srcset attribute for at least two sources; null for fewer.

staticeditorSizes(array $meta, string $baseUrl, string $fullUrl, array $names, Closure $downsize): array#

The image sizes an attachment offers the editor, each with orientation. @param Closure(string): (array|false) $downsize

$downsizeClosure(string): (array|false)
staticoldThumbnail(string $imagefile, string $thumb): ?array#

The old thumbnail an image's metadata names (its `thumb`), as a file beside the image with its size, while it is still there (probe image-downsize).

@return array{0: string, 1: int, 2: int}|null the file's name, width and height

Internals 2

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

privatecropBox(int $origW, int $origH, int $destW, int $destH): array#

A cropped size's box: each side at most the original's, and a side asked as 0 drawn from the other in the original's proportion.

@return array{0: int, 1: int}
privatejoin(string $base, string $path): string#