create() public static method

Create an image instance from the given image path and size
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static create ( string | contao\File $image, array | integer $size = null ) : static
$image string | contao\File The image path or File instance
$size array | integer The image size as array (width, height, resize mode) or an tl_image_size ID
return static The created image instance
示例#1
0
 /**
  * Gibt den Pfad und die Abmessungen des angepassten Bilds zurück.
  * @param $strImageId
  * @param $strSize
  * @return mixed
  */
 public static function getImageData($strImageId, $strSize)
 {
     $objImg = \Contao\FilesModel::findByPk($strImageId);
     $arrSize = deserialize($strSize);
     $arrMeta = deserialize($objImg->meta);
     if ($arrMeta != null && isset($arrMeta[$GLOBALS['TL_LANGUAGE']])) {
         $arrData['meta'] = $arrMeta[$GLOBALS['TL_LANGUAGE']];
     } else {
         $arrData['meta']['title'] = $objImg->name;
     }
     if (!is_array($arrSize)) {
         $arrSize = getimagesize($objImg->path);
         $imageObj = \Contao\Image::create($objImg->path, array($arrSize[0], $arrSize[1], $arrSize[2]));
         $imageObj->executeResize();
         $arrData['path'] = $imageObj->getResizedPath();
     }
     if (!isset($arrData['path'])) {
         $arrData['path'] = $objImg->path;
     }
     $arrData['name'] = $objImg->name;
     $arrData['width'] = $arrSize[0];
     $arrData['height'] = $arrSize[1];
     return $arrData;
 }
 /**
  * Recursively render the filetree
  *
  * @param string  $path
  * @param integer $intMargin
  * @param boolean $mount
  * @param boolean $blnProtected
  * @param array   $arrFound
  *
  * @return string
  */
 protected function renderFiletree($path, $intMargin, $mount = false, $blnProtected = true, $arrFound = array())
 {
     // Invalid path
     if (!is_dir($path)) {
         return '';
     }
     // Make sure that $this->varValue is an array (see #3369)
     if (!is_array($this->varValue)) {
         $this->varValue = array($this->varValue);
     }
     static $session;
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     $flag = substr($this->strField, 0, 2);
     $node = 'tree_' . $this->strTable . '_' . $this->strField;
     $xtnode = 'tree_' . $this->strTable . '_' . $this->strName;
     // Get session data and toggle nodes
     if (\Input::get($flag . 'tg')) {
         $session[$node][\Input::get($flag . 'tg')] = isset($session[$node][\Input::get($flag . 'tg')]) && $session[$node][\Input::get($flag . 'tg')] == 1 ? 0 : 1;
         $objSessionBag->replace($session);
         $this->redirect(preg_replace('/(&(amp;)?|\\?)' . $flag . 'tg=[^& ]*/i', '', \Environment::get('request')));
     }
     $return = '';
     $intSpacing = 20;
     $files = array();
     $folders = array();
     $level = $intMargin / $intSpacing + 1;
     // Mount folder
     if ($mount) {
         $folders = array($path);
     } else {
         foreach (scan($path) as $v) {
             if (strncmp($v, '.', 1) === 0) {
                 continue;
             }
             if (is_dir($path . '/' . $v)) {
                 $folders[] = $path . '/' . $v;
             } else {
                 $files[] = $path . '/' . $v;
             }
         }
     }
     natcasesort($folders);
     $folders = array_values($folders);
     natcasesort($files);
     $files = array_values($files);
     // Sort descending (see #4072)
     if ($this->sort == 'desc') {
         $folders = array_reverse($folders);
         $files = array_reverse($files);
     }
     $folderClass = $this->files || $this->filesOnly ? 'tl_folder' : 'tl_file';
     // Process folders
     for ($f = 0, $c = count($folders); $f < $c; $f++) {
         $content = scan($folders[$f]);
         $currentFolder = str_replace(TL_ROOT . '/', '', $folders[$f]);
         $countFiles = count($content);
         // Check whether there are subfolders or files
         foreach ($content as $file) {
             if (strncmp($file, '.', 1) === 0) {
                 --$countFiles;
             } elseif (!$this->files && !$this->filesOnly && is_file($folders[$f] . '/' . $file)) {
                 --$countFiles;
             } elseif (!empty($arrFound) && !in_array($currentFolder . '/' . $file, $arrFound) && !preg_grep('/^' . preg_quote($currentFolder . '/' . $file, '/') . '\\//', $arrFound)) {
                 --$countFiles;
             }
         }
         if (!empty($arrFound) && $countFiles < 1 && !in_array($currentFolder, $arrFound)) {
             continue;
         }
         $tid = md5($folders[$f]);
         $folderAttribute = 'style="margin-left:20px"';
         $session[$node][$tid] = is_numeric($session[$node][$tid]) ? $session[$node][$tid] : 0;
         $currentFolder = str_replace(TL_ROOT . '/', '', $folders[$f]);
         $blnIsOpen = !empty($arrFound) || $session[$node][$tid] == 1 || count(preg_grep('/^' . preg_quote($currentFolder, '/') . '\\//', $this->varValue)) > 0;
         $return .= "\n    " . '<li class="' . $folderClass . ' toggle_select hover-div"><div class="tl_left" style="padding-left:' . $intMargin . 'px">';
         // Add a toggle button if there are childs
         if ($countFiles > 0) {
             $folderAttribute = '';
             $img = $blnIsOpen ? 'folMinus.svg' : 'folPlus.svg';
             $alt = $blnIsOpen ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode'];
             $return .= '<a href="' . \Backend::addToUrl($flag . 'tg=' . $tid) . '" title="' . \StringUtil::specialchars($alt) . '" onclick="return AjaxRequest.toggleFiletree(this,\'' . $xtnode . '_' . $tid . '\',\'' . $currentFolder . '\',\'' . $this->strField . '\',\'' . $this->strName . '\',' . $level . ')">' . \Image::getHtml($img, '', 'style="margin-right:2px"') . '</a>';
         }
         $protected = $blnProtected;
         // Check whether the folder is public
         if ($protected === true && array_search('.public', $content) !== false) {
             $protected = false;
         }
         $folderImg = $protected ? 'folderCP.svg' : 'folderC.svg';
         $folderLabel = $this->files || $this->filesOnly ? '<strong>' . \StringUtil::specialchars(basename($currentFolder)) . '</strong>' : \StringUtil::specialchars(basename($currentFolder));
         // Add the current folder
         $return .= \Image::getHtml($folderImg, '', $folderAttribute) . ' <a href="' . \Backend::addToUrl('fn=' . $this->urlEncode($currentFolder)) . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $folderLabel . '</a></div> <div class="tl_right">';
         // Add a checkbox or radio button
         if (!$this->filesOnly) {
             switch ($this->fieldType) {
                 case 'checkbox':
                     $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . md5($currentFolder) . '" class="tl_tree_checkbox" value="' . \StringUtil::specialchars($currentFolder) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFolder, $this->varValue) . '>';
                     break;
                 case 'radio':
                     $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . md5($currentFolder) . '" class="tl_tree_radio" value="' . \StringUtil::specialchars($currentFolder) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFolder, $this->varValue) . '>';
                     break;
             }
         }
         $return .= '</div><div style="clear:both"></div></li>';
         // Call the next node
         if ($blnIsOpen) {
             $return .= '<li class="parent" id="' . $xtnode . '_' . $tid . '"><ul class="level_' . $level . '">';
             $return .= $this->renderFiletree($folders[$f], $intMargin + $intSpacing, false, $protected, $arrFound);
             $return .= '</ul></li>';
         }
     }
     // Process files
     if ($this->files || $this->filesOnly) {
         for ($h = 0, $c = count($files); $h < $c; $h++) {
             $thumbnail = '';
             $currentFile = str_replace(TL_ROOT . '/', '', $files[$h]);
             $currentEncoded = $this->urlEncode($currentFile);
             $objFile = new \File($currentFile);
             if (!empty($this->arrValidFileTypes) && !in_array($objFile->extension, $this->arrValidFileTypes)) {
                 continue;
             }
             // Ignore files not matching the search criteria
             if (!empty($arrFound) && !in_array($currentFile, $arrFound)) {
                 continue;
             }
             $return .= "\n    " . '<li class="tl_file toggle_select hover-div"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px">';
             $thumbnail .= ' <span class="tl_gray">(' . $this->getReadableSize($objFile->filesize);
             if ($objFile->width && $objFile->height) {
                 $thumbnail .= ', ' . $objFile->width . 'x' . $objFile->height . ' px';
             }
             $thumbnail .= ')</span>';
             // Generate thumbnail
             if ($objFile->isImage && $objFile->viewHeight > 0 && \Config::get('thumbnails') && ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth'))) {
                 $imageObj = \Image::create($currentEncoded, array(400, $objFile->height && $objFile->height < 50 ? $objFile->height : 50, 'box'));
                 $importantPart = $imageObj->getImportantPart();
                 $thumbnail .= '<br>' . \Image::getHtml($imageObj->executeResize()->getResizedPath(), '', 'style="margin:0 0 2px -19px"');
                 if ($importantPart['x'] > 0 || $importantPart['y'] > 0 || $importantPart['width'] < $objFile->width || $importantPart['height'] < $objFile->height) {
                     $thumbnail .= ' ' . \Image::getHtml($imageObj->setZoomLevel(100)->setTargetWidth(320)->setTargetHeight($objFile->height && $objFile->height < 40 ? $objFile->height : 40)->executeResize()->getResizedPath(), '', 'style="margin:0 0 2px 0;vertical-align:bottom"');
                 }
             }
             $return .= \Image::getHtml($objFile->icon, $objFile->mime) . ' ' . \StringUtil::convertEncoding(\StringUtil::specialchars(basename($currentFile)), \Config::get('characterSet')) . $thumbnail . '</div> <div class="tl_right">';
             // Add checkbox or radio button
             switch ($this->fieldType) {
                 case 'checkbox':
                     $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . md5($currentFile) . '" class="tl_tree_checkbox" value="' . \StringUtil::specialchars($currentFile) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFile, $this->varValue) . '>';
                     break;
                 case 'radio':
                     $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . md5($currentFile) . '" class="tl_tree_radio" value="' . \StringUtil::specialchars($currentFile) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFile, $this->varValue) . '>';
                     break;
             }
             $return .= '</div><div style="clear:both"></div></li>';
         }
     }
     return $return;
 }
示例#3
0
 /**
  * Render the file tree and return it as HTML string
  *
  * @param string  $path
  * @param integer $intMargin
  * @param boolean $mount
  * @param boolean $blnProtected
  * @param array   $arrClipboard
  * @param array   $arrFound
  *
  * @return string
  */
 protected function generateTree($path, $intMargin, $mount = false, $blnProtected = true, $arrClipboard = null, $arrFound = array())
 {
     static $session;
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     // Get the session data and toggle the nodes
     if (\Input::get('tg')) {
         $session['filetree'][\Input::get('tg')] = isset($session['filetree'][\Input::get('tg')]) && $session['filetree'][\Input::get('tg')] == 1 ? 0 : 1;
         $objSessionBag->replace($session);
         $this->redirect(preg_replace('/(&(amp;)?|\\?)tg=[^& ]*/i', '', \Environment::get('request')));
     }
     $return = '';
     $files = array();
     $folders = array();
     $intSpacing = 20;
     $level = $intMargin / $intSpacing + 1;
     // Mount folder
     if ($mount) {
         $folders = array($path);
     } else {
         foreach (scan($path) as $v) {
             if (strncmp($v, '.', 1) === 0) {
                 continue;
             }
             if (is_file($path . '/' . $v)) {
                 $files[] = $path . '/' . $v;
             } else {
                 if ($v == '__new__') {
                     $this->Files->rmdir(str_replace(TL_ROOT . '/', '', $path) . '/' . $v);
                 } else {
                     $folders[] = $path . '/' . $v;
                 }
             }
         }
         natcasesort($folders);
         $folders = array_values($folders);
         natcasesort($files);
         $files = array_values($files);
     }
     // Folders
     for ($f = 0, $c = count($folders); $f < $c; $f++) {
         $md5 = substr(md5($folders[$f]), 0, 8);
         $content = scan($folders[$f]);
         $currentFolder = str_replace(TL_ROOT . '/', '', $folders[$f]);
         $session['filetree'][$md5] = is_numeric($session['filetree'][$md5]) ? $session['filetree'][$md5] : 0;
         $currentEncoded = $this->urlEncode($currentFolder);
         $countFiles = count($content);
         // Subtract files that will not be shown
         foreach ($content as $file) {
             if (strncmp($file, '.', 1) === 0) {
                 --$countFiles;
             } elseif (!empty($arrFound) && !in_array($currentFolder . '/' . $file, $arrFound) && !preg_grep('/^' . preg_quote($currentFolder . '/' . $file, '/') . '\\//', $arrFound)) {
                 --$countFiles;
             }
         }
         if (!empty($arrFound) && $countFiles < 1 && !in_array($currentFolder, $arrFound)) {
             continue;
         }
         $return .= "\n  " . '<li class="tl_folder click2edit toggle_select hover-div"><div class="tl_left" style="padding-left:' . ($intMargin + ($countFiles < 1 ? 20 : 0)) . 'px">';
         // Add a toggle button if there are childs
         if ($countFiles > 0) {
             $img = !empty($arrFound) || $session['filetree'][$md5] == 1 ? 'folMinus.gif' : 'folPlus.gif';
             $alt = !empty($arrFound) || $session['filetree'][$md5] == 1 ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode'];
             $return .= '<a href="' . $this->addToUrl('tg=' . $md5) . '" title="' . specialchars($alt) . '" onclick="Backend.getScrollOffset(); return AjaxRequest.toggleFileManager(this, \'filetree_' . $md5 . '\', \'' . $currentFolder . '\', ' . $level . ')">' . \Image::getHtml($img, '', 'style="margin-right:2px"') . '</a>';
         }
         $protected = $blnProtected;
         // Check whether the folder is public
         if ($protected === true && array_search('.public', $content) !== false) {
             $protected = false;
         }
         $folderImg = $protected ? 'folderCP.gif' : 'folderC.gif';
         // Add the current folder
         $strFolderNameEncoded = \StringUtil::convertEncoding(specialchars(basename($currentFolder)), \Config::get('characterSet'));
         $return .= \Image::getHtml($folderImg, '') . ' <a href="' . $this->addToUrl('node=' . $currentEncoded) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '"><strong>' . $strFolderNameEncoded . '</strong></a></div> <div class="tl_right">';
         // Paste buttons
         if ($arrClipboard !== false && \Input::get('act') != 'select') {
             $imagePasteInto = \Image::getHtml('pasteinto.gif', $GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][0]);
             $return .= ($arrClipboard['mode'] == 'cut' || $arrClipboard['mode'] == 'copy') && preg_match('/^' . preg_quote($arrClipboard['id'], '/') . '/i', $currentFolder) ? \Image::getHtml('pasteinto_.gif') : '<a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=2&amp;pid=' . $currentEncoded . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][1]) . '" onclick="Backend.getScrollOffset()">' . $imagePasteInto . '</a> ';
         } else {
             // Do not display buttons for mounted folders
             if ($this->User->isAdmin || !in_array($currentFolder, $this->User->filemounts)) {
                 $return .= \Input::get('act') == 'select' ? '<input type="checkbox" name="IDS[]" id="ids_' . md5($currentEncoded) . '" class="tl_tree_checkbox" value="' . $currentEncoded . '">' : $this->generateButtons(array('id' => $currentEncoded, 'popupWidth' => 600, 'popupHeight' => 123, 'fileNameEncoded' => $strFolderNameEncoded), $this->strTable);
             }
             // Upload button
             if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] && \Input::get('act') != 'select') {
                 $return .= ' <a href="' . $this->addToUrl('&amp;act=move&amp;mode=2&amp;pid=' . $currentEncoded) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG']['tl_files']['uploadFF'], $currentEncoded)) . '">' . \Image::getHtml('new.gif', $GLOBALS['TL_LANG'][$this->strTable]['move'][0]) . '</a>';
             }
         }
         $return .= '</div><div style="clear:both"></div></li>';
         // Call the next node
         if (!empty($content) && (!empty($arrFound) || $session['filetree'][$md5] == 1)) {
             $return .= '<li class="parent" id="filetree_' . $md5 . '"><ul class="level_' . $level . '">';
             $return .= $this->generateTree($folders[$f], $intMargin + $intSpacing, false, $protected, $arrClipboard, $arrFound);
             $return .= '</ul></li>';
         }
     }
     // Process files
     for ($h = 0, $c = count($files); $h < $c; $h++) {
         $thumbnail = '';
         $popupWidth = 600;
         $popupHeight = 161;
         $currentFile = str_replace(TL_ROOT . '/', '', $files[$h]);
         $objFile = new \File($currentFile);
         if (!empty($this->arrValidFileTypes) && !in_array($objFile->extension, $this->arrValidFileTypes)) {
             continue;
         }
         // Ignore files not matching the search criteria
         if (!empty($arrFound) && !in_array($currentFile, $arrFound)) {
             continue;
         }
         $currentEncoded = $this->urlEncode($currentFile);
         $return .= "\n  " . '<li class="tl_file click2edit toggle_select hover-div"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px">';
         // Generate the thumbnail
         if ($objFile->isImage) {
             if ($objFile->viewHeight > 0) {
                 if ($objFile->width && $objFile->height) {
                     $popupWidth = $objFile->width > 600 ? $objFile->width + 61 : 661;
                     $popupHeight = $objFile->height + 210;
                 } else {
                     $popupWidth = 661;
                     $popupHeight = 625 / $objFile->viewWidth * $objFile->viewHeight + 210;
                 }
                 $thumbnail .= ' <span class="tl_gray">(' . $this->getReadableSize($objFile->filesize);
                 if ($objFile->width && $objFile->height) {
                     $thumbnail .= ', ' . $objFile->width . 'x' . $objFile->height . ' px';
                 }
                 $thumbnail .= ')</span>';
                 if (\Config::get('thumbnails') && ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth'))) {
                     $imageObj = \Image::create($currentEncoded, array(400, $objFile->height && $objFile->height < 50 ? $objFile->height : 50, 'box'));
                     $importantPart = $imageObj->getImportantPart();
                     $thumbnail .= '<br><img src="' . TL_FILES_URL . $imageObj->executeResize()->getResizedPath() . '" alt="" style="margin:0 0 2px -19px">';
                     if ($importantPart['x'] > 0 || $importantPart['y'] > 0 || $importantPart['width'] < $objFile->width || $importantPart['height'] < $objFile->height) {
                         $thumbnail .= ' <img src="' . TL_FILES_URL . $imageObj->setZoomLevel(100)->setTargetWidth(320)->setTargetHeight($objFile->height && $objFile->height < 40 ? $objFile->height : 40)->executeResize()->getResizedPath() . '" alt="" style="margin:0 0 2px 0">';
                     }
                 }
             } else {
                 $popupHeight = 360;
                 // dimensionless SVGs are rendered at 300x150px, so the popup needs to be 150px + 210px high
             }
         } else {
             $thumbnail .= ' <span class="tl_gray">(' . $this->getReadableSize($objFile->filesize) . ')</span>';
         }
         $strFileNameEncoded = \StringUtil::convertEncoding(specialchars(basename($currentFile)), \Config::get('characterSet'));
         // No popup links for templates and in the popup file manager
         if ($this->strTable == 'tl_templates' || \Input::get('popup')) {
             $return .= \Image::getHtml($objFile->icon) . ' ' . $strFileNameEncoded . $thumbnail . '</div> <div class="tl_right">';
         } else {
             $return .= '<a href="' . $currentEncoded . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['view']) . '" target="_blank">' . \Image::getHtml($objFile->icon, $objFile->mime) . '</a> ' . $strFileNameEncoded . $thumbnail . '</div> <div class="tl_right">';
         }
         // Buttons
         if ($arrClipboard !== false && \Input::get('act') != 'select') {
             $_buttons = '&nbsp;';
         } else {
             $_buttons = \Input::get('act') == 'select' ? '<input type="checkbox" name="IDS[]" id="ids_' . md5($currentEncoded) . '" class="tl_tree_checkbox" value="' . $currentEncoded . '">' : $this->generateButtons(array('id' => $currentEncoded, 'popupWidth' => $popupWidth, 'popupHeight' => $popupHeight, 'fileNameEncoded' => $strFileNameEncoded), $this->strTable);
         }
         $return .= $_buttons . '</div><div style="clear:both"></div></li>';
     }
     return $return;
 }
示例#4
0
 /**
  * Add an image to a template
  *
  * @param object  $objTemplate   The template object to add the image to
  * @param array   $arrItem       The element or module as array
  * @param integer $intMaxWidth   An optional maximum width of the image
  * @param string  $strLightboxId An optional lightbox ID
  */
 public static function addImageToTemplate($objTemplate, $arrItem, $intMaxWidth = null, $strLightboxId = null)
 {
     try {
         $objFile = new \File($arrItem['singleSRC']);
     } catch (\Exception $e) {
         $objFile = new \stdClass();
         $objFile->imageSize = false;
     }
     $imgSize = $objFile->imageSize;
     $size = deserialize($arrItem['size']);
     if ($intMaxWidth === null) {
         $intMaxWidth = TL_MODE == 'BE' ? 320 : \Config::get('maxImageWidth');
     }
     $arrMargin = TL_MODE == 'BE' ? array() : deserialize($arrItem['imagemargin']);
     // Store the original dimensions
     $objTemplate->width = $imgSize[0];
     $objTemplate->height = $imgSize[1];
     // Adjust the image size
     if ($intMaxWidth > 0) {
         // Subtract the margins before deciding whether to resize (see #6018)
         if (is_array($arrMargin) && $arrMargin['unit'] == 'px') {
             $intMargin = $arrMargin['left'] + $arrMargin['right'];
             // Reset the margin if it exceeds the maximum width (see #7245)
             if ($intMaxWidth - $intMargin < 1) {
                 $arrMargin['left'] = '';
                 $arrMargin['right'] = '';
             } else {
                 $intMaxWidth = $intMaxWidth - $intMargin;
             }
         }
         if ($size[0] > $intMaxWidth || !$size[0] && !$size[1] && $imgSize[0] > $intMaxWidth) {
             // See #2268 (thanks to Thyon)
             $ratio = $size[0] && $size[1] ? $size[1] / $size[0] : $imgSize[1] / $imgSize[0];
             $size[0] = $intMaxWidth;
             $size[1] = floor($intMaxWidth * $ratio);
         }
     }
     // Disable responsive images in the back end (see #7875)
     if (TL_MODE == 'BE') {
         unset($size[2]);
     }
     try {
         $src = \Image::create($arrItem['singleSRC'], $size)->executeResize()->getResizedPath();
         $picture = \Picture::create($arrItem['singleSRC'], $size)->getTemplateData();
         if ($src !== $arrItem['singleSRC']) {
             $objFile = new \File(rawurldecode($src));
         }
     } catch (\Exception $e) {
         \System::log('Image "' . $arrItem['singleSRC'] . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         $src = '';
         $picture = array('img' => array('src' => '', 'srcset' => ''), 'sources' => array());
     }
     // Image dimensions
     if (($imgSize = $objFile->imageSize) !== false) {
         $objTemplate->arrSize = $imgSize;
         $objTemplate->imgSize = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"';
     }
     $picture['alt'] = specialchars($arrItem['alt']);
     $picture['title'] = specialchars($arrItem['title']);
     $objTemplate->picture = $picture;
     // Provide an ID for single lightbox images in HTML5 (see #3742)
     if ($strLightboxId === null && $arrItem['fullsize']) {
         $strLightboxId = 'lightbox[' . substr(md5($objTemplate->getName() . '_' . $arrItem['id']), 0, 6) . ']';
     }
     // Float image
     if ($arrItem['floating'] != '') {
         $objTemplate->floatClass = ' float_' . $arrItem['floating'];
     }
     // Do not override the "href" key (see #6468)
     $strHrefKey = $objTemplate->href != '' ? 'imageHref' : 'href';
     // Image link
     if ($arrItem['imageUrl'] != '' && TL_MODE == 'FE') {
         $objTemplate->{$strHrefKey} = $arrItem['imageUrl'];
         $objTemplate->attributes = '';
         if ($arrItem['fullsize']) {
             // Open images in the lightbox
             if (preg_match('/\\.(jpe?g|gif|png)$/', $arrItem['imageUrl'])) {
                 // Do not add the TL_FILES_URL to external URLs (see #4923)
                 if (strncmp($arrItem['imageUrl'], 'http://', 7) !== 0 && strncmp($arrItem['imageUrl'], 'https://', 8) !== 0) {
                     $objTemplate->{$strHrefKey} = TL_FILES_URL . \System::urlEncode($arrItem['imageUrl']);
                 }
                 $objTemplate->attributes = ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"';
             } else {
                 $objTemplate->attributes = ' target="_blank"';
             }
         }
     } elseif ($arrItem['fullsize'] && TL_MODE == 'FE') {
         $objTemplate->{$strHrefKey} = TL_FILES_URL . \System::urlEncode($arrItem['singleSRC']);
         $objTemplate->attributes = ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"';
     }
     // Do not urlEncode() here because getImage() already does (see #3817)
     $objTemplate->src = TL_FILES_URL . $src;
     $objTemplate->alt = specialchars($arrItem['alt']);
     $objTemplate->title = specialchars($arrItem['title']);
     $objTemplate->linkTitle = $objTemplate->title;
     $objTemplate->fullsize = $arrItem['fullsize'] ? true : false;
     $objTemplate->addBefore = $arrItem['floating'] != 'below';
     $objTemplate->margin = static::generateMargin($arrMargin);
     $objTemplate->caption = $arrItem['caption'];
     $objTemplate->singleSRC = $arrItem['singleSRC'];
     $objTemplate->addImage = true;
 }