API / Minn\Runtime / AttachmentImages

AttachmentImages final class

Minn\Runtime\AttachmentImages · public/minn/src/Minn/Runtime/AttachmentImages.php · 422 lines

An attachment's image as WordPress's media functions make it: the registered sizes, a size fitted to a box, the file for a size (or an icon), the srcset and sizes pair, the loading attributes an image earns where it sits, the img element itself, and the site icon.

Public

staticsizes(): array#

The registered sizes (_minn_image_sizes): the four from the options, then the ones add_image_size added.

@return array<string, array<string, mixed>>
staticadditionalSizes(): array#

The sizes plugins and themes added (wp_get_additional_image_sizes), kept where they read them: $_wp_additional_image_sizes.

@return array<string, mixed>
staticconstrain(mixed $width, mixed $height, mixed $maxWidth = 0, mixed $maxHeight = 0): mixed#

Dimensions fitted inside a box (wp_constrain_dimensions), through wp_constrain_dimensions when there is a box.

@return array{0: int, 1: int}
staticmatchesRatio(mixed $sourceWidth, mixed $sourceHeight, mixed $targetWidth, mixed $targetHeight): bool#

Whether two sizes share a ratio (wp_image_matches_ratio): the wider one, fitted into the other's box, comes within a pixel of it.

staticconstrainForEditor(mixed $width, mixed $height, mixed $size = 'medium', mixed $context = NULL): mixed#

Dimensions fitted for the editor to a named or given size (image_constrain_size_for_editor), within editor_max_image_size.

@return array{0: int, 1: int}
staticintermediate(mixed $postId, mixed $size = 'thumbnail'): mixed#

An attachment's file for a size (image_get_intermediate_size), as image_get_intermediate_size leaves it; false for none.

staticdownsize(mixed $id, mixed $size = 'medium'): mixed#

An image attachment at a size (image_downsize): its address, width, height and whether that is a resized copy, unless image_downsize answers first; false for no image.

staticsrc(mixed $attachmentId, mixed $size = 'thumbnail', mixed $icon = false): mixed#

An attachment's image at a size, or its icon when asked (wp_get_attachment_image_src), as wp_get_attachment_image_src leaves it.

staticsizeFromMeta(mixed $sizeName, mixed $imageMeta): mixed#

A named size's dimensions from an image's metadata (_wp_get_image_size_from_meta): full for the original; false for one it lacks.

staticsrcset(mixed $sizeArray, mixed $imageSrc, mixed $imageMeta, mixed $attachmentId = 0): mixed#

The srcset of an image's sizes with its ratio (wp_calculate_image_srcset), as wp_calculate_image_srcset leaves the sources; false for none.

staticsizesAttribute(mixed $size, mixed $imageSrc = NULL, mixed $imageMeta = NULL, mixed $attachmentId = 0): mixed#

The sizes attribute for an image's width (wp_calculate_image_sizes), as wp_calculate_image_sizes leaves it; false without a width.

staticstartsWithAuto(mixed $sizes): bool#

Whether a sizes list starts with auto, alone or before a comma, in any case (wp_sizes_attribute_includes_valid_auto).

staticdimensionAttributes(mixed $width, mixed $height): string#

The width and height attributes for an image (image_hwstring), each when set.

staticlazyLoading(mixed $tagName, mixed $context): mixed#

Whether lazy loading is on for a tag in a context (wp_lazy_loading_enabled): images and iframes, as wp_lazy_loading_enabled leaves it.

staticloadingAttributes(mixed $tagName, mixed $attr, mixed $context): mixed#

The loading attributes an image or iframe earns (wp_get_loading_optimization_attributes), unless a plugin answers first: decoding async for an image; with both dimensions set, the caller's own priority and loading, else where it sits.

staticearnedPriority(string $tagName, array $attr): array#

Fetch priority high for an image large enough to deserve it, while no other image has taken it.

$attrarray<string, mixed>
@return array<string, string>
staticimageAttributes(int $attachmentId, array $attr, string $src, int $width, int $height, string $context = 'wp_get_attachment_image'): array#

The loading attributes and the srcset and sizes pair an attachment's image carries unless the caller set them.

$attrarray<string, mixed>
@return array<string, mixed>
staticimage(mixed $attachmentId, mixed $size = 'thumbnail', mixed $icon = false, mixed $attr = ''): mixed#

An attachment's img element at a size (wp_get_attachment_image): its class, alt text, loading attributes and srcset, through wp_get_attachment_image_attributes and wp_get_attachment_image; empty for none.

staticsiteIconUrl(mixed $size = 512, mixed $url = '', mixed $blogId = 0): mixed#

The site icon's address at a size (get_site_icon_url), the address given when the site has none; as get_site_icon_url leaves it.

statichasSiteIcon(mixed $blogId = 0): bool#

Whether the site has an icon (has_site_icon).

Internals 2

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

privateasked(string $tagName, array $attr, ?string $priority, array $optimization): ?array#

What a caller's own fetchpriority high or loading settles; null when it named neither. Only an image takes high priority, and an element that names a loading other than lazy is never made lazy.

$attrarray<string, mixed>
$optimizationarray<string, mixed>
@return array<string, mixed>|null
privatebyPlace(string $tagName, array $attr, string $context, array $optimization): array#

Where an element sits settles the rest. One in a header context is in view: never lazy, one of the eager images. Inside a page's template, or its main loop, an image shares the engine's budget: three eager images, the first one large enough to deserve it high priority. Anything else waits, where lazy loading is on.

$attrarray<string, mixed>
$optimizationarray<string, mixed>
@return array<string, mixed>