TYPO3 CMS  TYPO3_6-2
LocalImageProcessor.php
Go to the documentation of this file.
1 <?php
3 
17 use \TYPO3\CMS\Core\Resource, \TYPO3\CMS\Core\Utility;
18 
23 
27  protected $logger;
28 
32  public function __construct() {
34  $logManager = Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager');
35  $this->logger = $logManager->getLogger(__CLASS__);
36  }
37 
44  public function canProcessTask(TaskInterface $task) {
45  $canProcessTask = $task->getType() === 'Image';
46  $canProcessTask = $canProcessTask & in_array($task->getName(), array('Preview', 'CropScaleMask'));
47  return $canProcessTask;
48  }
49 
56  public function processTask(TaskInterface $task) {
57  if (!$this->canProcessTask($task)) {
58  throw new \InvalidArgumentException('Cannot process task of type "' . $task->getType() . '.' . $task->getName() . '"', 1350570621);
59  }
60  $helper = $this->getHelperByTaskName($task->getName());
61  try {
62  $result = $helper->process($task);
63  if ($result === NULL) {
64  $task->setExecuted(TRUE);
65  $task->getTargetFile()->setUsesOriginalFile();
66  } elseif (!empty($result['filePath']) && file_exists($result['filePath'])) {
67  $task->setExecuted(TRUE);
68  $imageDimensions = $this->getGraphicalFunctionsObject()->getImageDimensions($result['filePath']);
69  $task->getTargetFile()->setName($task->getTargetFileName());
70  $task->getTargetFile()->updateProperties(
71  array('width' => $imageDimensions[0], 'height' => $imageDimensions[1], 'size' => filesize($result['filePath']), 'checksum' => $task->getConfigurationChecksum())
72  );
73  $task->getTargetFile()->updateWithLocalFile($result['filePath']);
74  } else {
75  // Seems we have no valid processing result
76  $task->setExecuted(FALSE);
77  }
78  } catch (\Exception $e) {
79  $task->setExecuted(FALSE);
80  }
81  }
82 
88  protected function getHelperByTaskName($taskName) {
89  switch ($taskName) {
90  case 'Preview':
91  $helper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper', $this);
92  break;
93  case 'CropScaleMask':
94  $helper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Processing\LocalCropScaleMaskHelper', $this);
95  break;
96  default:
97  throw new \InvalidArgumentException('Cannot find helper for task name: "' . $taskName . '"', 1353401352);
98  }
99 
100  return $helper;
101  }
102 
111  public function wrapFileName($inputName) {
112  if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
113  $currentLocale = setlocale(LC_CTYPE, 0);
114  setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
115  $escapedInputName = escapeshellarg($inputName);
116  setlocale(LC_CTYPE, $currentLocale);
117  } else {
118  $escapedInputName = escapeshellarg($inputName);
119  }
120  return $escapedInputName;
121  }
122 
137  public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3) {
138  if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
139  throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952);
140  }
141  // Creates the basis for the error image
142  if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
143  $im = imagecreatefrompng(PATH_typo3 . 'gfx/notfound_thumb.png');
144  } else {
145  $im = imagecreatefromgif(PATH_typo3 . 'gfx/notfound_thumb.gif');
146  }
147  // Sets background color and print color.
148  $white = imageColorAllocate($im, 255, 255, 255);
149  $black = imageColorAllocate($im, 0, 0, 0);
150  // Prints the text strings with the build-in font functions of GD
151  $x = 0;
152  $font = 0;
153  if ($textline1) {
154  imagefilledrectangle($im, $x, 9, 56, 16, $white);
155  imageString($im, $font, $x, 9, $textline1, $black);
156  }
157  if ($textline2) {
158  imagefilledrectangle($im, $x, 19, 56, 26, $white);
159  imageString($im, $font, $x, 19, $textline2, $black);
160  }
161  if ($textline3) {
162  imagefilledrectangle($im, $x, 29, 56, 36, $white);
163  imageString($im, $font, $x, 29, substr($textline3, -14), $black);
164  }
165  // Outputting the image stream and exit
166  if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
167  imagePng($im, $filename);
168  } else {
169  imageGif($im, $filename);
170  }
171  }
172 
176  protected function getGraphicalFunctionsObject() {
177  static $graphicalFunctionsObject = NULL;
178 
179  if ($graphicalFunctionsObject === NULL) {
180  $graphicalFunctionsObject = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
181  }
182 
183  return $graphicalFunctionsObject;
184  }
185 }
getTemporaryImageWithText($filename, $textline1, $textline2, $textline3)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]