2 namespace TYPO3\CMS\Backend\Sprite;
31 .###NAMESPACE###-###SPRITENAME### {
32 background-image: url(\'###SPRITEURL###\') !important;
33 height: ###DEFAULTHEIGHT###px;
34 width: ###DEFAULTWIDTH###px;
44 .backgroundsize .###NAMESPACE###-###SPRITENAME### {
45 background-image: url(\'###SPRITEURL###\') !important;
46 background-size:###BGWIDTH### ###BGHEIGHT###;
55 background-position: -###LEFT###px -###TOP###px !important;
214 $this->spriteFolder = $folder;
226 $this->cssFolder = $folder;
238 $this->enableHighDensitySprite = $enable;
250 $this->omitSpriteNameInIconName = is_bool($value) ? $value :
false;
262 $this->space = (int)$value;
274 $this->includeTimestampInCSS = is_bool($value) ? $value :
true;
288 $iconArray = array();
289 foreach ($inputFolder as $folder) {
291 $iconArray = array_merge($iconArray, $this->
getFolder($folder));
306 if (!$this->omitSpriteNameInIconName) {
313 if ($this->enableHighDensitySprite) {
316 $this->generateCSS();
317 $iconNames = array_keys($this->iconsData);
320 'spriteImage' => PATH_site . $this->spriteFolder . $this->spriteName .
'.png',
321 'cssFile' => PATH_site . $this->cssFolder . $this->spriteName .
'.css',
322 'iconNames' => $iconNames
331 protected function generateCSS()
336 if ($this->includeTimestampInCSS) {
337 $timestamp =
'?' . time();
342 $markerArray = array(
343 '###NAMESPACE###' => $this->nameSpace,
344 '###DEFAULTWIDTH###' => $this->defaultWidth,
345 '###DEFAULTHEIGHT###' => $this->defaultHeight,
346 '###SPRITENAME###' =>
'',
347 '###SPRITEURL###' => $spritePathForCSS ? $spritePathForCSS .
'/' :
''
349 $markerArray[
'###SPRITEURL###'] .= $this->spriteName .
'.png' . $timestamp;
350 foreach ($this->spriteBases as $base) {
351 $markerArray[
'###SPRITENAME###'] = $base;
352 $cssData .= $templateService->substituteMarkerArray($this->templateSprite, $markerArray);
354 if ($this->enableHighDensitySprite) {
355 $highDensityMarkerArray = array_merge($markerArray, array(
356 '###BGWIDTH###' => $this->spriteWidth .
'px',
357 '###BGHEIGHT###' => $this->spriteHeight .
'px',
358 '###SPRITEURL###' => str_replace(
359 $this->spriteName .
'.png',
360 $this->spriteName .
'@x2.png',
361 $markerArray[
'###SPRITEURL###']
364 $cssData .= $templateService->substituteMarkerArray($this->templateSpriteHighDensity, $highDensityMarkerArray);
368 foreach ($this->iconsData as $data) {
369 $temp = $data[
'iconNameParts'];
371 $cssName = implode(
'-', $temp);
372 $markerArrayIcons = array(
373 '###NAMESPACE###' => $this->nameSpace,
374 '###ICONNAME###' => $cssName,
375 '###LEFT###' => $data[
'left'],
376 '###TOP###' => $data[
'top'],
377 '###SIZE_INFO###' =>
''
379 if ($data[
'height'] != $this->defaultHeight) {
380 $markerArrayIcons[
'###SIZE_INFO###'] .= TAB .
'height: ' . $data[
'height'] .
'px;' . LF;
382 if ($data[
'width'] != $this->defaultWidth) {
383 $markerArrayIcons[
'###SIZE_INFO###'] .= TAB .
'width: ' . $data[
'width'] .
'px;' . LF;
385 $cssData .= $templateService->substituteMarkerArray($this->templateIcon, $markerArrayIcons);
398 $this->cssFolder = str_replace(
'\\',
'/', $this->cssFolder);
399 $this->spriteFolder = str_replace(
'\\',
'/', $this->spriteFolder);
403 while (isset($cssPathSegments[$i]) && isset($graphicPathSegments[$i]) && $cssPathSegments[$i] == $graphicPathSegments[$i]) {
404 unset($cssPathSegments[$i]);
405 unset($graphicPathSegments[$i]);
408 foreach ($cssPathSegments as $key => $value) {
409 $cssPathSegments[$key] =
'..';
411 $completePath = array_merge($cssPathSegments, $graphicPathSegments);
412 $path = implode(
'/', $completePath);
424 $filePath = PATH_site . $this->spriteFolder . $this->spriteName .
'.png';
427 $newSprite = imagecreatetruecolor($this->spriteWidth, $this->spriteHeight);
428 imagesavealpha($newSprite,
true);
430 imagefill($newSprite, 0, 0, imagecolorallocatealpha($newSprite, 0, 255, 255, 127));
431 foreach ($this->iconsData as $icon) {
432 $function =
'imagecreatefrom' . strtolower($icon[
'fileExtension']);
433 if (function_exists($function)) {
434 $currentIcon = $function($icon[
'fileName']);
435 imagecopy($newSprite, $currentIcon, $icon[
'left'], $icon[
'top'], 0, 0, $icon[
'width'], $icon[
'height']);
438 imagepng($newSprite, $tempSprite);
451 $filePath = PATH_site . $this->spriteFolder . $this->spriteName .
'@x2.png';
454 $newSprite = imagecreatetruecolor($this->spriteWidth * 2, $this->spriteHeight * 2);
455 imagesavealpha($newSprite,
true);
457 imagefill($newSprite, 0, 0, imagecolorallocatealpha($newSprite, 0, 255, 255, 127));
458 foreach ($this->iconsData as $icon) {
459 $function =
'imagecreatefrom' . strtolower($icon[
'fileExtension']);
460 if (function_exists($function)) {
461 if ($icon[
'fileNameHighDensity'] !==
false) {
463 $currentIcon = $function($icon[
'fileNameHighDensity']);
464 imagecopy($newSprite, $currentIcon, $icon[
'left'] * 2, $icon[
'top'] * 2, 0, 0, $icon[
'width'] * 2, $icon[
'height'] * 2);
467 $currentIcon = $function($icon[
'fileName']);
468 imagecopyresized($newSprite, $currentIcon, $icon[
'left'] * 2, $icon[
'top'] * 2, 0, 0, $icon[
'width'] * 2, $icon[
'height'] * 2, $icon[
'width'], $icon[
'height']);
472 imagepng($newSprite, $tempSprite);
484 foreach ($this->iconSizes as $sizeTag => $count) {
486 $rowWidth = (int)ceil(sqrt($count)) * $size[
'width'];
487 while (isset($sizes[$rowWidth])) {
490 $sizes[$rowWidth] = $sizeTag;
496 foreach ($sizes as $sizeTag) {
500 $rowSize = ceil(sqrt($this->iconSizes[$sizeTag]));
501 $rowWidth = $rowSize * $size[
'width'] + ($rowSize - 1) * $this->space;
504 natsort($this->iconNamesPerSize[$sizeTag]);
505 foreach ($this->iconNamesPerSize[$sizeTag] as $iconName) {
506 if ($rowCounter == $rowSize - 1) {
508 }
elseif ($rowCounter == 0) {
510 $currentTop += $size[
'height'];
516 $this->iconsData[$iconName][
'left'] = $currentLeft;
517 $this->iconsData[$iconName][
'top'] = $currentTop;
518 $currentLeft += $size[
'width'];
522 $currentTop += $size[
'height'];
525 $this->spriteHeight = $currentTop;
538 if (!$this->omitSpriteNameInIconName) {
541 $resultArray = array();
542 foreach ($subFolders as $folder) {
543 if ($folder !==
'.svn') {
545 if (!in_array($folder, $this->spriteBases) && !empty($icons) && $folder !==
'') {
546 $this->spriteBases[] = $folder;
548 foreach ($icons as $icon) {
549 $fileInfo = pathinfo($icon);
550 $iconName = ($folder ? $folder .
'-' :
'') . $fileInfo[
'filename'];
551 if (!$this->omitSpriteNameInIconName) {
552 $iconName = $this->spriteName .
'-' . $iconName;
554 $resultArray[$iconName] = $directoryPath . $folder .
'/' . $icon;
569 foreach ($files as $iconName => $iconFile) {
571 if (!in_array($iconNameParts[0], $this->spriteBases)) {
572 $this->spriteBases[] = $iconNameParts[0];
574 $fileInfo = @pathinfo((PATH_site . $iconFile));
575 $imageInfo = @getimagesize((PATH_site . $iconFile));
576 $this->iconsData[$iconName] = array(
577 'iconName' => $iconName,
578 'iconNameParts' => $iconNameParts,
579 'singleName' => $fileInfo[
'filename'],
580 'fileExtension' => $fileInfo[
'extension'],
581 'fileName' => PATH_site . $iconFile,
582 'width' => $imageInfo[0],
583 'height' => $imageInfo[1],
586 'fileNameHighDensity' =>
false
588 if ($this->enableHighDensitySprite) {
589 $highDensityFile = str_replace(
'.' . $fileInfo[
'extension'],
'@x2.' . $fileInfo[
'extension'], $iconFile);
590 if (@file_exists(PATH_site . $highDensityFile)) {
591 $this->iconsData[$iconName][
'fileNameHighDensity'] = $highDensityFile;
594 $sizeTag = $imageInfo[0] .
'x' . $imageInfo[1];
595 if (isset($this->iconSizes[$sizeTag])) {
596 $this->iconSizes[$sizeTag] += 1;
598 $this->iconSizes[$sizeTag] = 1;
599 $this->iconNamesPerSize[$sizeTag] = array();
601 $this->iconNamesPerSize[$sizeTag][] = $iconName;
604 asort($this->iconSizes);
605 $defaultSize = $this->
explodeSizeTag(array_pop(array_keys($this->iconSizes)));
606 $this->defaultWidth = $defaultSize[
'width'];
607 $this->defaultHeight = $defaultSize[
'height'];