getOption('siteurl') . $element['src']; } $element['width'] = str_replace('px', '', $element['width']); $element['height'] = str_replace('px', '', $element['height']); $original_width = 0; if (is_numeric($element['width']) && is_numeric($element['height'])) { $element['width'] = (int)$element['width']; $element['height'] = (int)$element['height']; $original_width = $element['width']; $element = self::adjustImageDimensions($element, $column_base_width); } // If image was downsized because of column width set width to aways fill full column (e.g. on mobile) $style = ''; if ($element['fullWidth'] === true && $original_width > $element['width']) { $style = 'style="width:100%"'; } $image_template = ' ' . EHelper::escapeHtmlAttr($element['alt']) . ' '; if (!empty($element['link'])) { $image_template = '' . trim($image_template) . ''; } $align = 'center'; if (!empty($element['styles']['block']['textAlign']) && in_array($element['styles']['block']['textAlign'], ['left', 'right'])) { $align = $element['styles']['block']['textAlign']; } $template = ' ' . trim($image_template) . ' '; return $template; } public static function adjustImageDimensions($element, $column_base_width) { $padded_width = StylesHelper::$padding_width * 2; // scale image to fit column width if ($element['width'] > $column_base_width) { $ratio = $element['width'] / $column_base_width; $element['width'] = $column_base_width; $element['height'] = (int)ceil($element['height'] / $ratio); } // resize image if the image is padded and wider than padded column width if ($element['fullWidth'] === false && $element['width'] > ($column_base_width - $padded_width) ) { $ratio = $element['width'] / ($column_base_width - $padded_width); $element['width'] = $column_base_width - $padded_width; $element['height'] = (int)ceil($element['height'] / $ratio); } return $element; } }