'attachment' => $attachment,
],
'$allocated_height' => Media::getAllocatedHeightByMedia($attachment),
+ '$allocated_max_width' => ($attachment['preview-width'] ?? $attachment['width']) . 'px',
]);
}, $s);
}
if ($attachment['filetype'] == 'image') {
$preview_url = Post\Media::getPreviewUrlForId($attachment['id'], ($attachment['width'] > $attachment['height']) ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE);
+ $attachment['preview-width'] = ($attachment['width'] > $attachment['height']) ? Proxy::PIXEL_MEDIUM : Proxy::PIXEL_LARGE;
} elseif (!empty($attachment['preview'])) {
$preview_url = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_LARGE);
+ $attachment['preview-width'] = Proxy::PIXEL_LARGE;
} else {
$preview_url = '';
}
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
'$image' => $images[0],
'$allocated_height' => Media::getAllocatedHeightByMedia($images[0]['attachment']),
+ '$allocated_max_width' => ($images[0]['attachment']['preview-width'] ?? $images[0]['attachment']['width']) . 'px',
]);
}
*/
public static function getAllocatedHeightByMedia(array $media): string
{
- if (!empty($media['preview-height'])) {
- $allocated_height = (100 * $media['preview-height'] / $media['preview-width']) . '%';
- } else {
- $allocated_height = (100 * $media['height'] / $media['width']) . '%';
- }
-
- return $allocated_height;
+ return (100 * $media['height'] / $media['width']) . '%';
}
}
-{{* $image.widthRatio is only set in the context of Model\Item->makeImageGrid *}}
-<figure class="img-allocated-height" style="width: {{if $image.widthRatio}}{{$image.widthRatio}}%{{else}}auto{{/if}}; padding-bottom: {{$allocated_height}}">
+{{* The padding-top height allocation trick only works if the <figure> fills its parent's width completely or with flex. 🤷♂️
+ As a result, we need to add a wrapping element for non-flex (non-image grid) environments, mostly single-image cases.
+ *}}
+{{if $allocated_max_width}}
+<div style="max-width: {{$allocated_max_width|default:"auto"}};">
+{{/if}}
+
+<figure class="img-allocated-height" style="width: {{$allocated_width|default:"auto"}}; padding-bottom: {{$allocated_height}}">
{{if $image.preview}}
<a data-fancybox="{{$image.uri_id}}" href="{{$image.attachment.url}}">
<img src="{{$image.preview}}" alt="{{$image.attachment.description}}" title="{{$image.attachment.description}}">
<img src="{{$image.src}}" alt="{{$image.attachment.description}}" title="{{$image.attachment.description}}">
{{/if}}
</figure>
+
+{{if $allocated_max_width}}
+</div>
+{{/if}}
<div class="imagegrid-row" style="height: {{$images[0].commonHeightRatio}}%">
{{foreach $images as $image}}
{{* The absolute pixel value in the calc() should be mirrored from the .imagegrid-row column-gap value *}}
- {{include file="content/image.tpl" image=$image allocated_height="calc(`$image.heightRatio * $image.widthRatio / 100`% - 5px / `$column_size`)"}}
+ {{include file="content/image.tpl"
+ image=$image
+ allocated_height="calc(`$image.heightRatio * $image.widthRatio / 100`% - 5px / `$column_size`)"
+ allocated_width="`$image.widthRatio`%"
+ }}
{{/foreach}}
</div>
{{/foreach}}