2 namespace TYPO3\CMS\Frontend\Imaging;
157 public function start($conf,
$data)
159 if (is_array($conf)) {
160 $this->setup = $conf;
163 $this->cObj->start($this->data);
170 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'tslib/class.tslib_gifbuilder.php'][
'gifbuilder-ConfPreProcess'])) {
171 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'tslib/class.tslib_gifbuilder.php'][
'gifbuilder-ConfPreProcess'] as $_funcRef) {
177 $this->charRangeMap = array();
178 if (is_array(
$GLOBALS[
'TSFE']->tmpl->setup[
'_GIFBUILDER.'][
'charRangeMap.'])) {
179 foreach (
$GLOBALS[
'TSFE']->tmpl->setup[
'_GIFBUILDER.'][
'charRangeMap.'] as $cRMcfgkey => $cRMcfg) {
180 if (is_array($cRMcfg)) {
182 $cRMkey =
$GLOBALS[
'TSFE']->tmpl->setup[
'_GIFBUILDER.'][
'charRangeMap.'][substr($cRMcfgkey, 0, -1)];
183 $this->charRangeMap[$cRMkey] = array();
184 $this->charRangeMap[$cRMkey][
'charMapConfig'] = $cRMcfg[
'charMapConfig.'];
185 $this->charRangeMap[$cRMkey][
'cfgKey'] = substr($cRMcfgkey, 0, -1);
186 $this->charRangeMap[$cRMkey][
'multiplicator'] = (double) $cRMcfg[
'fontSizeMultiplicator'];
187 $this->charRangeMap[$cRMkey][
'pixelSpace'] = (int)$cRMcfg[
'pixelSpaceFontSizeRef'];
194 if ($conf[
'backColor.'] || $conf[
'backColor']) {
195 $this->setup[
'backColor'] = isset($this->setup[
'backColor.']) ? trim($this->cObj->stdWrap($this->setup[
'backColor'], $this->setup[
'backColor.'])) : $this->setup[
'backColor'];
197 if (!$this->setup[
'backColor']) {
198 $this->setup[
'backColor'] =
'white';
200 if ($conf[
'transparentColor.'] || $conf[
'transparentColor']) {
201 $this->setup[
'transparentColor_array'] = isset($this->setup[
'transparentColor.']) ? explode(
'|', trim($this->cObj->stdWrap($this->setup[
'transparentColor'], $this->setup[
'transparentColor.']))) : explode(
'|', trim($this->setup[
'transparentColor']));
203 if (isset($this->setup[
'transparentBackground.'])) {
204 $this->setup[
'transparentBackground'] = $this->cObj->stdWrap($this->setup[
'transparentBackground'], $this->setup[
'transparentBackground.']);
206 if (isset($this->setup[
'reduceColors.'])) {
207 $this->setup[
'reduceColors'] = $this->cObj->stdWrap($this->setup[
'reduceColors'], $this->setup[
'reduceColors.']);
210 if (isset($this->setup[
'XY.'])) {
211 $this->setup[
'XY'] = $this->cObj->stdWrap($this->setup[
'XY'], $this->setup[
'XY.']);
213 if (!$this->setup[
'XY']) {
214 $this->setup[
'XY'] =
'120,50';
218 foreach ($sKeyArray as $theKey) {
219 $theValue = $this->setup[$theKey];
220 if ((
int)$theKey && ($conf = $this->setup[$theKey .
'.'])) {
224 if ($this->setup[$theKey .
'.'] = $this->
checkTextObj($conf)) {
226 $maxWidth = isset($this->setup[$theKey .
'.'][
'maxWidth.']) ? $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'maxWidth'], $this->setup[$theKey .
'.'][
'maxWidth.']) : $this->setup[$theKey .
'.'][
'maxWidth'];
228 $this->setup[$theKey .
'.'][
'fontSize'] = $this->
fontResize($this->setup[$theKey .
'.']);
231 $txtInfo = $this->
calcBBox($this->setup[$theKey .
'.']);
232 $this->setup[$theKey .
'.'][
'BBOX'] = $txtInfo;
233 $this->objBB[$theKey] = $txtInfo;
234 $this->setup[$theKey .
'.'][
'imgMap'] = 0;
238 $fileInfo = $this->getResource($conf[
'file'], $conf[
'file.']);
240 $this->combinedFileNames[] = preg_replace(
'/\\.[[:alnum:]]+$/',
'', basename($fileInfo[3]));
241 if ($fileInfo[
'processedFile'] instanceof ProcessedFile) {
243 $this->setup[$theKey .
'.'][
'file'] = $fileInfo[
'processedFile']->getForLocalProcessing(
false);
244 }
elseif (!isset($fileInfo[
'origFile']) && $fileInfo[
'originalFile'] instanceof File) {
247 $originalFile = $fileInfo[
'originalFile'];
248 $this->setup[$theKey .
'.'][
'file'] = $originalFile->getForLocalProcessing(
false);
251 $this->setup[$theKey .
'.'][
'file'] = $fileInfo[3];
253 $this->setup[$theKey .
'.'][
'BBOX'] = $fileInfo;
254 $this->objBB[$theKey] = $fileInfo;
256 $maskInfo = $this->getResource($conf[
'mask'], $conf[
'mask.']);
259 if ($maskInfo[
'processedFile'] instanceof ProcessedFile) {
260 $this->setup[$theKey .
'.'][
'mask'] = $maskInfo[
'processedFile']->getForLocalProcessing(
false);
261 }
elseif (!isset($maskInfo[
'origFile']) && $maskInfo[
'originalFile'] instanceof File) {
263 $originalFile = $maskInfo[
'originalFile'];
264 $this->setup[$theKey .
'.'][
'mask'] = $originalFile->getForLocalProcessing(
false);
266 $this->setup[$theKey .
'.'][
'mask'] = $maskInfo[3];
269 $this->setup[$theKey .
'.'][
'mask'] =
'';
273 unset($this->setup[$theKey .
'.']);
280 $cObj->start($this->data);
281 if (!
$cObj->checkIf($conf[
'if.'])) {
282 unset($this->setup[$theKey]);
283 unset($this->setup[$theKey .
'.']);
284 unset($this->objBB[$theKey]);
290 $this->setup[
'XY'] = $this->
calcOffset($this->setup[
'XY']);
291 if (isset($this->setup[
'offset.'])) {
292 $this->setup[
'offset'] = $this->cObj->stdWrap($this->setup[
'offset'], $this->setup[
'offset.']);
294 $this->setup[
'offset'] = $this->
calcOffset($this->setup[
'offset']);
295 if (isset($this->setup[
'workArea.'])) {
296 $this->setup[
'workArea'] = $this->cObj->stdWrap($this->setup[
'workArea'], $this->setup[
'workArea.']);
298 $this->setup[
'workArea'] = $this->
calcOffset($this->setup[
'workArea']);
299 foreach ($sKeyArray as $theKey) {
300 $theValue = $this->setup[$theKey];
301 if ((
int)$theKey && ($conf = $this->setup[$theKey .
'.'])) {
306 if (isset($this->setup[$theKey .
'.'][
'offset.'])) {
307 $this->setup[$theKey .
'.'][
'offset'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'offset'], $this->setup[$theKey .
'.'][
'offset.']);
308 unset($this->setup[$theKey .
'.'][
'offset.']);
310 if ($this->setup[$theKey .
'.'][
'offset']) {
311 $this->setup[$theKey .
'.'][
'offset'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'offset']);
317 if (isset($this->setup[$theKey .
'.'][
'dimensions.'])) {
318 $this->setup[$theKey .
'.'][
'dimensions'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'dimensions'], $this->setup[$theKey .
'.'][
'dimensions.']);
319 unset($this->setup[$theKey .
'.'][
'dimensions.']);
321 if ($this->setup[$theKey .
'.'][
'dimensions']) {
322 $this->setup[$theKey .
'.'][
'dimensions'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'dimensions']);
326 if (isset($this->setup[$theKey .
'.'][
'set.'])) {
327 $this->setup[$theKey .
'.'][
'set'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'set'], $this->setup[$theKey .
'.'][
'set.']);
328 unset($this->setup[$theKey .
'.'][
'set.']);
330 if ($this->setup[$theKey .
'.'][
'set']) {
331 $this->setup[$theKey .
'.'][
'set'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'set']);
335 if (isset($this->setup[$theKey .
'.'][
'crop.'])) {
336 $this->setup[$theKey .
'.'][
'crop'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'crop'], $this->setup[$theKey .
'.'][
'crop.']);
337 unset($this->setup[$theKey .
'.'][
'crop.']);
339 if ($this->setup[$theKey .
'.'][
'crop']) {
340 $this->setup[$theKey .
'.'][
'crop'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'crop']);
344 if (isset($this->setup[$theKey .
'.'][
'width.'])) {
345 $this->setup[$theKey .
'.'][
'width'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'width'], $this->setup[$theKey .
'.'][
'width.']);
346 unset($this->setup[$theKey .
'.'][
'width.']);
348 if ($this->setup[$theKey .
'.'][
'width']) {
349 $this->setup[$theKey .
'.'][
'width'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'width']);
351 if (isset($this->setup[$theKey .
'.'][
'height.'])) {
352 $this->setup[$theKey .
'.'][
'height'] = $this->cObj->stdWrap($this->setup[$theKey .
'.'][
'height'], $this->setup[$theKey .
'.'][
'height.']);
353 unset($this->setup[$theKey .
'.'][
'height.']);
355 if ($this->setup[$theKey .
'.'][
'height']) {
356 $this->setup[$theKey .
'.'][
'height'] = $this->
calcOffset($this->setup[$theKey .
'.'][
'height']);
364 $maxWidth = isset($this->setup[
'maxWidth.']) ? (int)$this->cObj->stdWrap($this->setup[
'maxWidth'], $this->setup[
'maxWidth.']) : (int)$this->setup[
'maxWidth'];
365 $maxHeight = isset($this->setup[
'maxHeight.']) ? (int)$this->cObj->stdWrap($this->setup[
'maxHeight'], $this->setup[
'maxHeight.']) : (int)$this->setup[
'maxHeight'];
391 $gifFileName = $this->fileName(
'GB/');
393 if (!file_exists($gifFileName)) {
398 $this->
output($gifFileName);
421 $this->saveAlphaLayer =
false;
423 $this->im = imagecreatetruecolor(
$XY[0],
$XY[1]);
427 if (!empty($this->setup[
'backColor']) && $this->setup[
'backColor'] ===
'transparent' && $this->png_truecolor && !$this->setup[
'reduceColors'] && (empty($this->setup[
'format']) || $this->setup[
'format'] ===
'png')) {
429 imagesavealpha($this->im,
true);
431 $transparentColor = imagecolorallocatealpha($this->im, 0, 0, 0, 127);
432 imagefill($this->im, 0, 0, $transparentColor);
434 $this->saveAlphaLayer =
true;
436 $this->setup[
'format'] =
'png';
440 $BGcols = $this->
convertColor($this->setup[
'backColor']);
441 $Bcolor = ImageColorAllocate($this->im, $BGcols[0], $BGcols[1], $BGcols[2]);
442 ImageFilledRectangle($this->im, 0, 0,
$XY[0],
$XY[1], $Bcolor);
445 if (is_array($this->setup)) {
447 foreach ($sKeyArray as $theKey) {
448 $theValue = $this->setup[$theKey];
449 if ((
int)$theKey && ($conf = $this->setup[$theKey .
'.'])) {
453 if ($theValue !==
'TEXT') {
454 $isStdWrapped = array();
455 foreach ($conf as $key => $value) {
456 $parameter = rtrim($key,
'.');
457 if (!$isStdWrapped[$parameter] && isset($conf[$parameter .
'.'])) {
458 $conf[$parameter] = $this->cObj->stdWrap($conf[$parameter], $conf[$parameter .
'.']);
459 $isStdWrapped[$parameter] = 1;
473 if (!$conf[
'hide']) {
474 if (is_array($conf[
'shadow.'])) {
475 $isStdWrapped = array();
476 foreach ($conf[
'shadow.'] as $key => $value) {
477 $parameter = rtrim($key,
'.');
478 if (!$isStdWrapped[$parameter] && isset($conf[$parameter .
'.'])) {
479 $conf[
'shadow.'][$parameter] = $this->cObj->stdWrap($conf[$parameter], $conf[$parameter .
'.']);
480 $isStdWrapped[$parameter] = 1;
483 $this->
makeShadow($this->im, $conf[
'shadow.'], $this->workArea, $conf);
485 if (is_array($conf[
'emboss.'])) {
486 $isStdWrapped = array();
487 foreach ($conf[
'emboss.'] as $key => $value) {
488 $parameter = rtrim($key,
'.');
489 if (!$isStdWrapped[$parameter] && isset($conf[$parameter .
'.'])) {
490 $conf[
'emboss.'][$parameter] = $this->cObj->stdWrap($conf[$parameter], $conf[$parameter .
'.']);
491 $isStdWrapped[$parameter] = 1;
494 $this->
makeEmboss($this->im, $conf[
'emboss.'], $this->workArea, $conf);
496 if (is_array($conf[
'outline.'])) {
497 $isStdWrapped = array();
498 foreach ($conf[
'outline.'] as $key => $value) {
499 $parameter = rtrim($key,
'.');
500 if (!$isStdWrapped[$parameter] && isset($conf[$parameter .
'.'])) {
501 $conf[
'outline.'][$parameter] = $this->cObj->stdWrap($conf[$parameter], $conf[$parameter .
'.']);
502 $isStdWrapped[$parameter] = 1;
505 $this->
makeOutline($this->im, $conf[
'outline.'], $this->workArea, $conf);
508 $this->
makeText($this->im, $conf, $this->workArea);
512 if ($this->setup[$conf[
'textObjNum']] ==
'TEXT' && ($txtConf = $this->
checkTextObj($this->setup[$conf[
'textObjNum'] .
'.']))) {
513 $this->
makeOutline($this->im, $conf, $this->workArea, $txtConf);
517 if ($this->setup[$conf[
'textObjNum']] ==
'TEXT' && ($txtConf = $this->
checkTextObj($this->setup[$conf[
'textObjNum'] .
'.']))) {
518 $this->
makeEmboss($this->im, $conf, $this->workArea, $txtConf);
522 if ($this->setup[$conf[
'textObjNum']] ==
'TEXT' && ($txtConf = $this->
checkTextObj($this->setup[$conf[
'textObjNum'] .
'.']))) {
523 $this->
makeShadow($this->im, $conf, $this->workArea, $txtConf);
527 $this->
makeBox($this->im, $conf, $this->workArea);
533 $this->
adjust($this->im, $conf);
536 $this->
crop($this->im, $conf);
539 $this->
scale($this->im, $conf);
546 if (isset($conf[
'clear'])) {
552 $this->
makeEllipse($this->im, $conf, $this->workArea);
559 if (!$this->saveAlphaLayer) {
560 if ($this->setup[
'transparentBackground']) {
562 $Bcolor = ImageColorClosest($this->im, $BGcols[0], $BGcols[1], $BGcols[2]);
563 imagecolortransparent($this->im, $Bcolor);
564 }
elseif (is_array($this->setup[
'transparentColor_array'])) {
568 $Tcolor = $this->
unifyColors($this->im, $this->setup[
'transparentColor_array'], (
int)$this->setup[
'transparentColor.'][
'closest']);
570 imagecolortransparent($this->im, $Tcolor);
595 $cObj->start($this->data);
596 $isStdWrapped = array();
597 foreach ($conf as $key => $value) {
598 $parameter = rtrim($key,
'.');
599 if (!$isStdWrapped[$parameter] && isset($conf[$parameter .
'.'])) {
600 $conf[$parameter] =
$cObj->stdWrap($conf[$parameter], $conf[$parameter .
'.']);
601 $isStdWrapped[$parameter] = 1;
604 $conf[
'fontFile'] = $this->
checkFile($conf[
'fontFile']);
605 if (!$conf[
'fontFile']) {
606 $conf[
'fontFile'] =
'typo3/sysext/core/Resources/Private/Font/nimbus.ttf';
608 if (!$conf[
'iterations']) {
609 $conf[
'iterations'] = 1;
611 if (!$conf[
'fontSize']) {
612 $conf[
'fontSize'] = 12;
615 if ($conf[
'spacing'] || $conf[
'wordSpacing']) {
618 if (!isset($conf[
'antiAlias'])) {
619 $conf[
'antiAlias'] = 1;
621 $conf[
'fontColor'] = trim($conf[
'fontColor']);
623 if (!$conf[
'doNotStripHTML']) {
624 $conf[
'text'] = strip_tags($conf[
'text']);
626 $this->combinedTextStrings[] = strip_tags($conf[
'text']);
628 if (!isset($conf[
'breakWidth']) || !$conf[
'breakWidth']) {
629 $tlen = (int)$conf[
'textMaxLength'] ?: 100;
630 if ($this->nativeCharset) {
631 $conf[
'text'] = $this->csConvObj->substr($this->nativeCharset, $conf[
'text'], 0, $tlen);
633 $conf[
'text'] = substr($conf[
'text'], 0, $tlen);
636 if ((
string)$conf[
'text'] !=
'') {
638 $fontBaseName = basename($conf[
'fontFile']);
639 if (is_array($this->charRangeMap[$fontBaseName])) {
641 if (!is_array($conf[
'splitRendering.'])) {
642 $conf[
'splitRendering.'] = array();
644 $cfgK = $this->charRangeMap[$fontBaseName][
'cfgKey'];
646 if (!isset($conf[
'splitRendering.'][$cfgK])) {
648 $conf[
'splitRendering.'][$cfgK] =
'charRange';
649 $conf[
'splitRendering.'][$cfgK .
'.'] = $this->charRangeMap[$fontBaseName][
'charMapConfig'];
651 if ($this->charRangeMap[$fontBaseName][
'multiplicator']) {
652 $conf[
'splitRendering.'][$cfgK .
'.'][
'fontSize'] = round($conf[
'fontSize'] * $this->charRangeMap[$fontBaseName][
'multiplicator']);
655 if ($this->charRangeMap[$fontBaseName][
'pixelSpace']) {
656 $travKeys = array(
'xSpaceBefore',
'xSpaceAfter',
'ySpaceBefore',
'ySpaceAfter');
657 foreach ($travKeys as $pxKey) {
658 if (isset($conf[
'splitRendering.'][$cfgK .
'.'][$pxKey])) {
659 $conf[
'splitRendering.'][$cfgK .
'.'][$pxKey] = round($conf[
'splitRendering.'][($cfgK .
'.')][$pxKey] * ($conf[
'fontSize'] / $this->charRangeMap[$fontBaseName][
'pixelSpace']));
665 if (is_array($conf[
'splitRendering.'])) {
666 foreach ($conf[
'splitRendering.'] as $key => $value) {
667 if (is_array($conf[
'splitRendering.'][$key])) {
668 if (isset($conf[
'splitRendering.'][$key][
'fontFile'])) {
669 $conf[
'splitRendering.'][$key][
'fontFile'] = $this->
checkFile($conf[
'splitRendering.'][$key][
'fontFile']);
694 foreach ($numbers as $key => $val) {
695 if ((
string)$val == (
string)(
int)$val) {
696 $value[$key] = (int)$val;
701 $string = implode(
',', $value);
714 public function getResource($file, $fileArray)
721 $cObj->start($this->data);
722 return $cObj->getImgResource($file, $fileArray);
735 return $GLOBALS[
'TSFE']->tmpl->getFileName($file);
748 public function fileName($pre)
752 $filePrefix = implode(
'_', array_merge($this->combinedTextStrings, $this->combinedFileNames));
753 $filePrefix = $basicFileFunctions->cleanFileName($filePrefix);
766 switch (strtolower($this->setup[
'format'])) {
792 $calculatedValue = 0;
794 foreach ($parts as $part) {
797 if (((
string)(
int)$theVal) == ((
string)$theVal)) {
798 $theVal = (int)$theVal;
799 }
elseif (
'[' . substr($theVal, 1, -1) .
']' == $theVal) {
800 $objParts = explode(
'.', substr($theVal, 1, -1));
802 if (isset($this->objBB[$objParts[0]])) {
803 if ($objParts[1] ==
'w') {
804 $theVal = $this->objBB[$objParts[0]][0];
805 }
elseif ($objParts[1] ==
'h') {
806 $theVal = $this->objBB[$objParts[0]][1];
807 }
elseif ($objParts[1] ==
'lineHeight') {
808 $theVal = $this->objBB[$objParts[0]][2][
'lineHeight'];
810 $theVal = (int)$theVal;
812 }
elseif (floatval($theVal)) {
813 $theVal = floatval($theVal);
818 $calculatedValue -= $theVal;
820 $calculatedValue += $theVal;
821 }
elseif ($sign ==
'/' && $theVal) {
822 $calculatedValue = $calculatedValue / $theVal;
824 $calculatedValue = $calculatedValue * $theVal;
825 }
elseif ($sign ==
'%' && $theVal) {
826 $calculatedValue %= $theVal;
829 return round($calculatedValue);
841 if (preg_match_all(
'#max\\(([^)]+)\\)#', $string, $matches)) {
842 foreach ($matches[1] as $index => $maxExpression) {
843 $string = str_replace($matches[0][$index], $this->
calculateMaximum($maxExpression), $string);
858 $maximum = !empty($parts) ? max($parts) : 0;