Fixed bug #15079 Feature: TYPO3 misses an SpriteGenerator (Thanks to Steffen Ritter)
authorSteffen Kamper <info@sk-typo3.de>
Sun, 8 Aug 2010 20:06:16 +0000 (20:06 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Sun, 8 Aug 2010 20:06:16 +0000 (20:06 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8536 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/core_autoload.php
t3lib/spritemanager/class.t3lib_spritemanager_spritegenerator.php [new file with mode: 0644]

index a1ba7ad..2cd0266 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-08-08  Steffen Kamper  <steffen@typo3.org>
+
+       * Fixed bug #15079 Feature: TYPO3 misses an SpriteGenerator (Thanks to Steffen Ritter)
+
 2010-08-08  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Fixed bug #12535: DAM-related: Element browser crashes as where-clause cannot be parsed
index afc0a19..833359c 100644 (file)
@@ -133,6 +133,7 @@ $t3libClasses = array(
        't3lib_utility_http' => PATH_t3lib . 'utility/class.t3lib_utility_http.php',
        't3lib_utility_mail' => PATH_t3lib . 'utility/class.t3lib_utility_mail.php',
        't3lib_spritemanager' => PATH_t3lib . 'class.t3lib_spritemanager.php',
+       't3lib_spritemanager_spritegenerator' => PATH_t3lib . 'spritemanager/class.t3lib_spritemanager_spritegenerator.php',
        't3lib_spritemanager_spriteicongenerator' => PATH_t3lib . 'interfaces/interface.t3lib_spritemanager_spriteicongenerator.php',
        't3lib_spritemanager_simplehandler' => PATH_t3lib . 'spritemanager/class.t3lib_spritemanager_simplehandler.php',
 );
diff --git a/t3lib/spritemanager/class.t3lib_spritemanager_spritegenerator.php b/t3lib/spritemanager/class.t3lib_spritemanager_spritegenerator.php
new file mode 100644 (file)
index 0000000..6e2a477
--- /dev/null
@@ -0,0 +1,608 @@
+<?php\r
+/***************************************************************\r
+*  Copyright notice\r
+*\r
+*  (c) 2010 Steffen Ritter <info@steffen-ritter.net>\r
+*  All rights reserved\r
+*\r
+*  This script is part of the TYPO3 project. The TYPO3 project is\r
+*  free software; you can redistribute it and/or modify\r
+*  it under the terms of the GNU General Public License as published by\r
+*  the Free Software Foundation; either version 2 of the License, or\r
+*  (at your option) any later version.\r
+*\r
+*  The GNU General Public License can be found at\r
+*  http://www.gnu.org/copyleft/gpl.html.\r
+*  A copy is found in the textfile GPL.txt and important notices to the license\r
+*  from the author is found in LICENSE.txt distributed with these scripts.\r
+*\r
+*\r
+*  This script is distributed in the hope that it will be useful,\r
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*  GNU General Public License for more details.\r
+*\r
+*  This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+\r
+/**\r
+ * sprite generator\r
+ *\r
+ * @author     Steffen Ritter <info@steffen-ritter.net>\r
+ * @package TYPO3\r
+ * @subpackage t3lib\r
+ */\r
+\r
+class t3lib_spritemanager_SpriteGenerator {\r
+       /**\r
+        * template creating CSS for the spritefile\r
+        *\r
+        * @var string\r
+        */\r
+       private $templateSprite = '\r
+.###NAMESPACE###-###SPRITENAME### {\r
+       background-image: url(\'###SPRITEURL###\');\r
+       height: ###DEFAULTHEIGHT###px;\r
+       width: ###DEFAULTWIDTH###px;\r
+}\r
+';\r
+\r
+       /**\r
+        *\r
+        * template creating CSS for position and size of a single icon\r
+        *\r
+        * @var string\r
+        */\r
+       private $templateIcon = '.###NAMESPACE###-###ICONNAME### {\r
+       background-position: -###LEFT###px -###TOP###px;\r
+       ###SIZE_INFO###\r
+}\r
+';\r
+\r
+       /**\r
+        * most common icon-width in the sprite\r
+        *\r
+        * @var int\r
+        */\r
+       private $defaultWidth  = 0;\r
+\r
+       /**\r
+        * most common icon-height in the sprite\r
+        *\r
+        * @var int\r
+        */\r
+       private $defaultHeight = 0;\r
+\r
+       /**\r
+        * calculated width of the sprite\r
+        *\r
+        * @var int\r
+        */\r
+       private $spriteWidth = 0;\r
+\r
+       /**\r
+        * calculated height of the sprite\r
+        * @var int\r
+        */\r
+       private $spriteHeight = 0;\r
+\r
+       /**\r
+        * sprite name, will be the filename, too\r
+        *\r
+        * @var string\r
+        */\r
+       private $spriteName = '';\r
+\r
+       /**\r
+        * the folder the sprite-images will be saved (relative to PATH_site)\r
+        *\r
+        * @var string\r
+        */\r
+       private $spriteFolder = 'typo3temp/sprites/';\r
+\r
+       /**\r
+        * the folder the sprite-cs will be saved (relative to PATH_site)\r
+        *\r
+        * @var string\r
+        */\r
+       private $cssFolder = 'typo3temp/sprites/';\r
+\r
+       /**\r
+        * the spriteName will not be included in icon names\r
+        *\r
+        * @var boolean\r
+        */\r
+       private $ommitSpriteNameInIconName = FALSE;\r
+\r
+       /**\r
+        * @var boolean\r
+        * @deprecated IE6 support will be dropped within 4.6 - then gifcopies are superflous\r
+        */\r
+       private $generateGIFCopy = TRUE;\r
+\r
+       /**\r
+        * namespace of css classes\r
+        *\r
+        * @var string\r
+        */\r
+       private $nameSpace = 't3-icon';\r
+\r
+       /**\r
+        * setting this to true, the timestamp of the creation will be included to the background import\r
+        * helps to easily rebuild sprites without cache problems\r
+        *\r
+        * @var boolean\r
+        */\r
+       private $includeTimestampInCSS = TRUE;\r
+\r
+       /**\r
+        * all bases/root-names included in the sprite which has to be in css\r
+        * as sprite to include the background-image\r
+        *\r
+        * @var array\r
+        */\r
+       private $spriteBases = array();\r
+\r
+       /**\r
+        * collects data about all icons to process\r
+        *\r
+        * @var array\r
+        */\r
+       private $iconsData = array();\r
+\r
+       /**\r
+        * collects all sizes of icons within this sprite and there count\r
+        *\r
+        * @var array\r
+        */\r
+       private $iconSizes = array();\r
+\r
+       /**\r
+        * maps icon-sizes to iconnames\r
+        *\r
+        * @var array\r
+        */\r
+       private $iconNamesPerSize = array();\r
+\r
+       /**\r
+        * space in px between to icons in the sprite (gap)\r
+        *\r
+        * @var int\r
+        */\r
+       private $space = 2;\r
+\r
+       /**\r
+        * Initializes the configuration of the spritegenerator\r
+        *\r
+        * @param string $spriteName    the name of the sprite to be generated\r
+        * @return void\r
+        */\r
+       public function __construct($spriteName) {\r
+               $this->spriteName = $spriteName;\r
+       }\r
+\r
+       /**\r
+        * Sets namespace of css code\r
+        *\r
+        * @param string $string\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setNamespace($nameSpace) {\r
+               $this->nameSpace = $nameSpace;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Sets the spritename\r
+        *\r
+        * @param string $spriteName    the name of the sprite to be generated\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setSpriteName($spriteName) {\r
+               $this->spriteName = $spriteName;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Sets the sprite-graphics target-folder\r
+        *\r
+        * @param string $folder the target folder where the generated sprite is stored\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setSpriteFolder($folder) {\r
+               $this->spriteFolder = $folder;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Sets the sprite-css target-folder\r
+        *\r
+        * @param string $folder the target folder where the generated CSS files are stored\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setCSSFolder($folder) {\r
+               $this->cssFolder = $folder;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Setter do enable the exclusion of the sprites-name from iconnames\r
+        *\r
+        * @param boolean $value\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setOmmitSpriteNameInIconName($value) {\r
+               $this->ommitSpriteNameInIconName = is_bool($value) ? $value : FALSE;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Setter to adjust how much space is between to icons in the sprite\r
+        *\r
+        * @param int $value\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setIconSpace($value) {\r
+               $this->space = intval($value);\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Setter to enable/disable generating a GIF-Copy of the sprite\r
+        *\r
+        * @param boolean $value\r
+        * @deprecated IE6 support will be dropped within 4.6 - then gifcopies are superflous\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setGenerateGifCopy($value) {\r
+               $this->generateGIFCopy = is_bool($value) ? $value : TRUE;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Setter for timestamp inclusion: imageFiles will be included with ?timestamp\r
+        *\r
+        * @param boolean $value\r
+        * @return t3lib_spritemanager_SpriteGenerator  an instance of $this, to enable chaining.\r
+        */\r
+       public function setIncludeTimestampInCSS($value) {\r
+               $this->includeTimestampInCSS = is_bool($value) ? $value : TRUE;\r
+               return $this;\r
+       }\r
+\r
+       /**\r
+        * Teads all png,gif,jpg files from the passed folder name (including 1 subfolder level)\r
+        * extracts size information and stores data in internal array,\r
+        * afterwards triggers sprite generation.\r
+        *\r
+        * @param array $inputFolder folder from which files are read\r
+        * @return      array\r
+        */\r
+       public function generateSpriteFromFolder(array $inputFolder) {\r
+               $iconArray = array();\r
+               foreach ($inputFolder as $folder) {\r
+                               // detect all files to be included in sprites\r
+                       $iconArray = array_merge(\r
+                               $iconArray,\r
+                               $this->getFolder($folder)\r
+                       );\r
+               }\r
+               return $this->generateSpriteFromArray($iconArray);\r
+       }\r
+\r
+       /**\r
+        * Method processes an array of files into an sprite,\r
+        * the array can be build from files within an folder or\r
+        * by hand (as the SpriteManager does)\r
+        *\r
+        * @param array $files array(icon name => icon file)\r
+        * @return array\r
+        */\r
+       public function generateSpriteFromArray(array $files) {\r
+               if (!$this->ommitSpriteNameInIconName) {\r
+                       $this->spriteBases[] = $this->spriteName;\r
+               }\r
+\r
+               $this->buildFileInformationCache($files);\r
+                       // calculate Icon Position in sprite\r
+               $this->calculateSpritePositions();\r
+\r
+               $this->generateGraphic();\r
+\r
+               $this->generateCSS();\r
+\r
+               $iconNames = array_keys($this->iconsData);\r
+               natsort($iconNames);\r
+\r
+               return array(\r
+                       'spriteImage'   => PATH_site . $this->spriteFolder . $this->spriteName . '.png',\r
+                       'spriteGifImage'=> PATH_site . $this->spriteFolder . $this->spriteName . '.gif',\r
+                       'cssFile'               => PATH_site . $this->cssFolder . $this->spriteName . '.css',\r
+                       'cssGif'                => PATH_site . $this->cssFolder . $this->spriteName . '-ie6.css',\r
+                       'iconNames'             => $iconNames\r
+               );\r
+       }\r
+\r
+       /**\r
+        * Generates the css files\r
+        *\r
+        * @return void\r
+        */\r
+       private function generateCSS() {\r
+               $cssData = '';\r
+               $cssIe6 = '';\r
+\r
+               if ($this->includeTimestampInCSS) {\r
+                       $timestamp = '?' . time();\r
+               } else {\r
+                       $timestamp = '';\r
+               }\r
+\r
+               $spritePathForCSS = $this->resolveSpritePath();\r
+\r
+               $markerArray = array(\r
+                       '###NAMESPACE###'               => $this->nameSpace,\r
+                       '###DEFAULTWIDTH###'    => $this->defaultWidth,\r
+                       '###DEFAULTHEIGHT###'   => $this->defaultHeight,\r
+                       '###SPRITENAME###'      => '',\r
+                       '###SPRITEURL###'               => ($spritePathForCSS ? $spritePathForCSS . '/' : '')\r
+               );\r
+               $markerArray['###SPRITEURL###'] .=  $this->spriteName . '.png' . $timestamp;\r
+\r
+               foreach ($this->spriteBases as $base) {\r
+                       $markerArray['###SPRITENAME###'] = $base;\r
+                       $cssData .= t3lib_parsehtml::substituteMarkerArray($this->templateSprite, $markerArray);\r
+               }\r
+\r
+               if ($this->generateGIFCopy) {\r
+                       $markerArray['###SPRITEURL###'] = str_replace('.png', '.gif', $markerArray['###SPRITEURL###']);\r
+                       foreach ($this->spriteBases as $base) {\r
+                               $cssIe6 .= t3lib_parsehtml::substituteMarkerArray($this->templateSprite, $markerArray);\r
+                       }\r
+               }\r
+\r
+               foreach ($this->iconsData as $key => $data) {\r
+                       $markerArrayIcons = array(\r
+                               '###NAMESPACE###'       => $this->nameSpace,\r
+                               '###ICONNAME###'        => $data['singleName'],\r
+                               '###LEFT###'            => $data['left'],\r
+                               '###TOP###'             => $data['top'],\r
+                               '###SIZE_INFO###'       => ''\r
+                       );\r
+                       if ($data['height'] != $this->defaultHeight) {\r
+                               $markerArrayIcons['###SIZE_INFO###'] .= TAB . 'height: ' . $data['height'] . 'px;' . LF;\r
+                       }\r
+                       if ($data['width'] != $this->defaultWidth) {\r
+                               $markerArrayIcons['###SIZE_INFO###'] .= TAB . 'width: ' . $data['width'] . 'px;' . LF;\r
+                       }\r
+                       $cssData .= t3lib_parsehtml::substituteMarkerArray($this->templateIcon, $markerArrayIcons);\r
+\r
+               }\r
+\r
+               t3lib_div::writeFile(PATH_site . $this->cssFolder . $this->spriteName . '.css', $cssData);\r
+               if ($this->generateGIFCopy) {\r
+                       t3lib_div::writeFile(PATH_site . $this->cssFolder . $this->spriteName . '-ie6.css', $cssIe6);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Compares image path to CSS path and creates the relative backpath from css to the sprites\r
+        *\r
+        * @return string\r
+        */\r
+       private function resolveSpritePath() {\r
+                       // Fix window paths\r
+               $this->cssFolder = str_replace('\\', '/', $this->cssFolder);\r
+               $this->spriteFolder = str_replace('\\', '/', $this->spriteFolder);\r
+\r
+               $cssPathSegments = t3lib_div::trimExplode('/', trim($this->cssFolder, '/'));\r
+               $graphicPathSegments = t3lib_div::trimExplode('/', trim($this->spriteFolder, '/'));\r
+\r
+               $i = 0;\r
+               while (isset($cssPathSegments[$i]) && isset($graphicPathSegments[$i]) &&\r
+                               $cssPathSegments[$i] == $graphicPathSegments[$i]) {\r
+                       unset($cssPathSegments[$i]);\r
+                       unset($graphicPathSegments[$i]);\r
+                       ++$i;\r
+               }\r
+               foreach ($cssPathSegments AS $key => $value) {\r
+                       $cssPathSegments[$key] = '..';\r
+               }\r
+               $completePath = array_merge($cssPathSegments, $graphicPathSegments);\r
+               $path = implode('/', $completePath);\r
+               return t3lib_div::resolveBackPath($path);\r
+       }\r
+\r
+       /**\r
+        * The actual sprite generator, renders the command for Im/GM and executes\r
+        *\r
+        * @return void\r
+        */\r
+       private function generateGraphic() {\r
+               $iconParameters = array();\r
+               $tempSprite = t3lib_div::tempnam($this->spriteName);\r
+\r
+               $filePath = array(\r
+                       'mainFile' => PATH_site . $this->spriteFolder . $this->spriteName . '.png',\r
+                       'gifFile'  => NULL\r
+               );\r
+                       // create black true color image with given size\r
+               $newSprite = imagecreatetruecolor($this->spriteWidth, $this->spriteHeight);\r
+               imagesavealpha($newSprite, true);\r
+                       // make it transparent\r
+               imagefill($newSprite, 0, 0, imagecolorallocatealpha($newSprite, 0, 255, 255, 127));\r
+               foreach ($this->iconsData AS $icon) {\r
+                       $function = 'imagecreatefrom' . strtolower($icon['fileExtension']);\r
+                       if(function_exists($function)) {\r
+                               $currentIcon = $function($icon['fileName']);\r
+                               imagecopy($newSprite, $currentIcon, $icon['left'], $icon['top'], 0, 0, $icon['width'], $icon['height']);\r
+                       }\r
+               }\r
+               imagepng($newSprite, $tempSprite . '.png');\r
+\r
+               if ($this->generateGIFCopy) {\r
+                       $filePath['gifFile'] = PATH_site . $this->spriteFolder . $this->spriteName . '.gif';\r
+                       $gifSprite = imagecreatetruecolor($this->spriteWidth, $this->spriteHeight);\r
+                               // make it transparent\r
+                       imagefill($gifSprite, 0, 0, imagecolorallocate($gifSprite, 127, 127, 127));\r
+                       foreach ($this->iconsData AS $icon) {\r
+                               $function = 'imagecreatefrom' . strtolower($icon['fileExtension']);\r
+                               if(function_exists($function)) {\r
+                                       $currentIcon = $function($icon['fileName']);\r
+                                       imagecopy($gifSprite, $currentIcon, $icon['left'], $icon['top'], 0, 0, $icon['width'], $icon['height']);\r
+                               }\r
+                       }\r
+                       imagecolortransparent($gifSprite, imagecolorallocate($gifSprite, 127, 127, 127));\r
+                       imagegif($gifSprite, $tempSprite . '.gif');\r
+               }\r
+\r
+               t3lib_div::upload_copy_move($tempSprite . '.png', $filePath['mainFile']);\r
+               t3lib_div::unlink_tempfile($tempSprite . '.png');\r
+               if ($this->generateGIFCopy) {\r
+                       t3lib_div::upload_copy_move($tempSprite . '.gif', $filePath['gifFile']);\r
+                       t3lib_div::unlink_tempfile($tempSprite . '.gif');\r
+               }\r
+       }\r
+       /**\r
+        * Arranges icons in sprites,\r
+        * afterwards all icons have information about ther position in sprite\r
+        */\r
+       private function calculateSpritePositions() {\r
+               $currentLeft = 0;\r
+               $currentTop  = 0;\r
+                       // calculate width of every icon-size-group\r
+               $sizes = array();\r
+               foreach ($this->iconSizes as $sizeTag => $count) {\r
+                       $size = $this->explodeSizeTag($sizeTag);\r
+                       $sizes[ceil(sqrt($count)) * $size['width']] = $sizeTag;\r
+               }\r
+                       // reverse sorting: widest group to top\r
+               krsort($sizes);\r
+                       // integerate all icons grouped by icons size into the sprite\r
+               foreach ($sizes as $sizeTag) {\r
+                       $size = $this->explodeSizeTag($sizeTag);\r
+                       $currentLeft = 0;\r
+                       $rowCounter = 0;\r
+\r
+                       $rowSize = ceil(sqrt($this->iconSizes[$sizeTag]));\r
+\r
+                       $rowWidth = $rowSize * $size['width'] + ($rowSize - 1) * $this->space;\r
+                       $this->spriteWidth = ($rowWidth > $this->spriteWidth ? $rowWidth : $this->spriteWidth);\r
+                       $firstLine = TRUE;\r
+\r
+                       natsort($this->iconNamesPerSize[$sizeTag]);\r
+                       foreach ($this->iconNamesPerSize[$sizeTag] as $iconName) {\r
+                               if ($rowCounter == $rowSize - 1) {\r
+                                       $rowCounter = -1;\r
+                               } elseif ($rowCounter == 0) {\r
+                                       if (!$firstLine) {\r
+                                               $currentTop += $size['height'];\r
+                                               $currentTop += $this->space;\r
+                                       }\r
+                                       $firstLine = FALSE;\r
+                                       $currentLeft = 0;\r
+                               }\r
+                               $this->iconsData[$iconName]['left'] = $currentLeft;\r
+                               $this->iconsData[$iconName]['top']  = $currentTop;\r
+\r
+                               $currentLeft += $size['width'];\r
+                               $currentLeft += $this->space;\r
+\r
+                               $rowCounter++;\r
+                       }\r
+                       $currentTop += $size['height'];\r
+                       $currentTop += $this->space;\r
+               }\r
+               $this->spriteHeight = $currentTop;\r
+       }\r
+\r
+       /**\r
+        * Function getFolder traverses the target directory,\r
+        * locates all iconFiles and collects them into an array\r
+        *\r
+        * @param string path to an folder which contains images\r
+        * @return array returns an array with all files key: iconname, value: fileName\r
+        */\r
+       private function getFolder($directoryPath) {\r
+               $subFolders = t3lib_div::get_dirs(PATH_site . $directoryPath);\r
+               if (!$this->ommitSpriteNameInIconName) {\r
+                       $subFolders[] = '';\r
+               }\r
+               $resultArray = array();\r
+\r
+               foreach ($subFolders as $folder) {\r
+                       if ($folder !== '.svn') {\r
+                               $icons = t3lib_div::getFilesInDir(PATH_site . $directoryPath . $folder . '/', 'gif,png,jpg');\r
+                               if (!in_array($folder, $this->spriteBases) && count($icons)) {\r
+                                       $this->spriteBases[] = $folder;\r
+                               }\r
+                               foreach ($icons AS $icon) {\r
+                                       $fileInfo = pathinfo($icon);\r
+\r
+                                       $iconName = ($folder ? $folder . '-' : '') . $fileInfo['filename'];\r
+                                       if (!$this->ommitSpriteNameInIconName) {\r
+                                               $iconName = $this->spriteName . '-' . $iconName;\r
+                                       }\r
+\r
+                                       $resultArray[$iconName] = $directoryPath . $folder . '/' . $icon;\r
+                               }\r
+                       }\r
+               }\r
+               return $resultArray;\r
+       }\r
+\r
+       /**\r
+        * Generates file information cache from file array\r
+        *\r
+        * @param array list of all files with their icon name\r
+        * @return void\r
+        */\r
+       private function buildFileInformationCache(array $files) {\r
+               foreach ($files as $iconName => $iconFile) {\r
+                       $fileInfo = pathinfo(PATH_site . $iconFile);\r
+                       $imageInfo = getimagesize(PATH_site . $iconFile);\r
+\r
+                       $this->iconsData[$iconName] = array(\r
+                               'iconName'              => $iconName,\r
+                               'singleName'    => $fileInfo['filename'],\r
+                               'fileExtension' => $fileInfo['extension'],\r
+                               'fileName'              => PATH_site . $iconFile,\r
+                               'width'                 => $imageInfo[0],\r
+                               'height'                => $imageInfo[1],\r
+                               'left'                  => 0,\r
+                               'top'                   => 0\r
+                       );\r
+\r
+                       $sizeTag = $imageInfo[0] . 'x' . $imageInfo[1];\r
+                       if (isset($this->iconSizes[$sizeTag])) {\r
+                               $this->iconSizes[$sizeTag] += 1;\r
+                       } else {\r
+                               $this->iconSizes[$sizeTag] = 1;\r
+                               $this->iconNamesPerSize[$sizeTag] = array();\r
+                       }\r
+                       $this->iconNamesPerSize[$sizeTag][] = $iconName;\r
+               }\r
+                       // find most common image size, save it as default\r
+               asort($this->iconSizes);\r
+               $defaultSize = $this->explodeSizeTag(array_pop(array_keys($this->iconSizes)));\r
+               $this->defaultWidth  = $defaultSize['width'];\r
+               $this->defaultHeight = $defaultSize['height'];\r
+       }\r
+\r
+       /**\r
+        * Transforms size tag into size array\r
+        *\r
+        * @param string  a size tag at the cache arrays\r
+        * @return array\r
+        */\r
+       private function explodeSizeTag($tag = '') {\r
+               $size = t3lib_div::trimExplode("x", $tag);\r
+               return array(\r
+                       'width' => $size[0],\r
+                       'height'=> $size[1]\r
+               );\r
+       }\r
+\r
+}\r
+?>
\ No newline at end of file