'*.jpg, *.png, *.gif',
'layout' => 'vertical',
'width' => '250px',
'height' => '10rem',
'gap' => '5px',
'cleanBottom' => false
);
$data = array_merge($defaults, (array) $data);
$data = (object) $data;
if ($files = FileUtils::fileDeclaration($data->globs, $Automad->Context->get())) {
$files = array_filter($files, function ($file) {
return FileUtils::fileIsImage($file);
});
if ($data->layout == 'vertical') {
$html = self::masonry($files, $data);
} else {
$html = self::flexbox($files, $data);
}
$style = '';
if (!empty($data->gap)) {
$style = " style='--am-gallery-gap: {$data->gap};'";
}
return '' . $html . '';
}
return '';
}
/**
* Render the actual flexbox markup.
*
* @param array $files
* @param object $data
* @return string The rendered HTML
*/
private static function flexbox(array $files, object $data): string {
// Normalize unit in case unit is missing.
$data->height = preg_replace('/^([\.\d]*)$/sm', '$1px', trim($data->height));
$pixelHeight = self::pixelValue($data->height);
$html = "
";
foreach ($files as $file) {
$Image = new Image($file, 0, 2 * $pixelHeight);
$caption = Str::stripTags(FileUtils::caption($file));
$file = Str::stripStart($file, AM_BASE_DIR);
$width = round($Image->width / 2);
$html .= <<< HTML
HTML;
}
$html .= '
';
return $html;
}
/**
* Render the actual masonry markup.
*
* @param array $files
* @param object $data
* @return string The rendered HTML
*/
private static function masonry(array $files, object $data): string {
// Use a factor of 0.85 to multiply with the row height of the grid to get a good
// result since the aspect ratio is dependent on the actual row width and not the
// minimum row width.
$masonryRowHeight = 20 * 0.85;
// Normalize unit in case unit is missing.
$data->width = preg_replace('/^([\.\d]*)$/sm', '$1px', trim($data->width));
$pixelWidth = self::pixelValue($data->width);
// Adding styles for devices smaller than width.
$maxWidth = $pixelWidth * 1.75;
$style = "";
$cleanBottom = '';
if ($data->cleanBottom) {
$cleanBottom = ' am-gallery-masonry-clean-bottom';
}
$html = $style .
'';
foreach ($files as $file) {
$Image = new Image($file, 2 * $pixelWidth);
$caption = Str::stripTags(FileUtils::caption($file));
$file = Str::stripStart($file, AM_BASE_DIR);
$span = round($Image->height / ($masonryRowHeight * 2));
$html .= <<< HTML
HTML;
}
$html .= '
';
return $html;
}
/**
* Convert dimension of any kind to pixels for resizing.
* Note that it is of course not possible to actually convert absolute units like px to
* relative units like % or vh, but conceptually a sensful approximation is required to resize
* images.
*
* @param string $valueString
* @return float The converted pixel value
*/
private static function pixelValue(string $valueString): float {
$pixel = floatval($valueString);
if (strpos($valueString, 'em') !== false) {
$pixel = 16 * floatval($valueString);
}
if (strpos($valueString, '%') !== false) {
$pixel = 10 * floatval($valueString);
}
if (strpos($valueString, 'vh') !== false) {
$pixel = 7 * floatval($valueString);
}
if (strpos($valueString, 'vw') !== false) {
$pixel = 14 * floatval($valueString);
}
return $pixel;
}
}
__halt_compiler();----SIGNATURE:----ncpCgsh8qxIHZ8M1yXpSP+DUCqqBQt0kXoetu1RS95ty2Uns6raruN+XmvHVy2/5mA7R2pJkTe704SyJO65lXSl5Raocz8DSzZ46svOKvl7cwBw7+hs1gTLZdTfTiFhvq0bVceIZvY2gjdjn1TLjx7N7Orap31q9Yzxv276DDPZDDMNnckNTEngZg9Krn7PTBmk/uv+kgp+7WOjYeY07McFByFzlhXIQbzIBJN2MroXfhOp2+kmSxwDPSVq6jhVp8o1uqq4BBVqRlODe5gZTqFXwAilhKOnPt9LvryrQ3bEG1BKblVhN2xjyvCX2YfVGPIWDOWLC1bTEl7ZD+o2FdSt040BOnMPgrtdvKMiCAf7nVbfRA2uyM80aDjCO4W0Xer022hTqe8WznojrxcdoI+TsdtLoSISrtRoeXWu6Ec9SCfC73a1yF0kHFpXZydKQ+GL1/y9psTJvD9vTd142jFAySwMrs27H1/qQg9ZXbKZyIQRtcIWnBYoDpAyxPNZ9toGzxijRpNh8MWsYcp+CQ6T9C/jdjWfRjbr2NRik+ZSpm/ZEzDLioR/a+WUBQa8FR1RXlLTLm5kfjHJ8rWndnohnUs4kRMt30vsj6PMPHynDoGewvQCrj0D2aBjhKkX7mXB3KYS+rxGM3Z8dN4UbhKv1cgV2M2e40yrSntdseZs=----ATTACHMENT:----MzYwNjY3NTc5Nzc5Mzg5MSAzNDEzNTI4ODg4NjQ4NzYxIDg2MzM4NzUzOTM2NDgwODk=