[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Tool / TestSetup.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Install\Controller\Action;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Test various system setup settings
22 */
23 class TestSetup extends Action\AbstractAction {
24
25 /**
26 * @var string Absolute path to image folder
27 */
28 protected $imageBasePath = '';
29
30 /**
31 * Executes the tool
32 *
33 * @return string Rendered content
34 */
35 protected function executeAction() {
36 $this->imageBasePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Public/Images/';
37
38 $actionMessages = array();
39 if (isset($this->postValues['set']['testMail'])) {
40 $actionMessages[] = $this->sendTestMail();
41 }
42
43 if (isset($this->postValues['set']['testTrueTypeFontDpi'])) {
44 $this->view->assign('trueTypeFontDpiTested', TRUE);
45 $actionMessages[] = $this->createTrueTypeFontDpiTestImage();
46 }
47
48 if (isset($this->postValues['set']['testConvertImageFormatsToJpg'])) {
49 $this->view->assign('convertImageFormatsToJpgTested', TRUE);
50 if ($this->isImageMagickEnabledAndConfigured()) {
51 $actionMessages[] = $this->convertImageFormatsToJpg();
52 } else {
53 $actionMessages[] = $this->imageMagickDisabledMessage();
54 }
55 }
56
57 if (isset($this->postValues['set']['testWriteGifAndPng'])) {
58 $this->view->assign('writeGifAndPngTested', TRUE);
59 if ($this->isImageMagickEnabledAndConfigured()) {
60 $actionMessages[] = $this->writeGifAndPng();
61 } else {
62 $actionMessages[] = $this->imageMagickDisabledMessage();
63 }
64 }
65
66 if (isset($this->postValues['set']['testScalingImages'])) {
67 $this->view->assign('scalingImagesTested', TRUE);
68 if ($this->isImageMagickEnabledAndConfigured()) {
69 $actionMessages[] = $this->scaleImages();
70 } else {
71 $actionMessages[] = $this->imageMagickDisabledMessage();
72 }
73 }
74
75 if (isset($this->postValues['set']['testCombiningImages'])) {
76 $this->view->assign('combiningImagesTested', TRUE);
77 if ($this->isImageMagickEnabledAndConfigured()) {
78 $actionMessages[] = $this->combineImages();
79 } else {
80 $actionMessages[] = $this->imageMagickDisabledMessage();
81 }
82 }
83
84 if (isset($this->postValues['set']['testGdlib'])) {
85 $this->view->assign('gdlibTested', TRUE);
86 $actionMessages[] = $this->gdlib();
87 }
88
89 $this->view->assign('actionMessages', $actionMessages);
90 $this->view->assign('senderEmailAddress', $this->getSenderEmailAddress());
91 $this->view->assign('imageConfiguration', $this->getImageConfiguration());
92
93 return $this->view->render();
94 }
95
96 /**
97 * Send a test mail to specified email address
98 *
99 * @return \TYPO3\CMS\Install\Status\StatusInterface
100 */
101 protected function sendTestMail() {
102 if (
103 !isset($this->postValues['values']['testEmailRecipient'])
104 || !GeneralUtility::validEmail($this->postValues['values']['testEmailRecipient'])
105 ) {
106 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
107 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
108 $message->setTitle('Mail not sent');
109 $message->setMessage('Given address is not a valid email address.');
110 } else {
111 $recipient = $this->postValues['values']['testEmailRecipient'];
112 $mailMessage = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
113 $mailMessage
114 ->addTo($recipient)
115 ->addFrom($this->getSenderEmailAddress(), 'TYPO3 CMS install tool')
116 ->setSubject('Test TYPO3 CMS mail delivery')
117 ->setBody('<html><body>html test content</body></html>')
118 ->addPart('TEST CONTENT')
119 ->send();
120 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
121 $message->setTitle('Test mail sent');
122 $message->setMessage('Recipient: ' . $recipient);
123 }
124 return $message;
125 }
126
127 /**
128 * Get sender address from configuration
129 * ['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']
130 * If this setting is empty fall back to 'no-reply@example.com'
131 *
132 * @return string Returns an email address
133 */
134 protected function getSenderEmailAddress() {
135 return !empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])
136 ? $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']
137 : 'no-reply@example.com';
138 }
139
140 /**
141 * Create true type font test image
142 *
143 * @return \TYPO3\CMS\Install\Status\StatusInterface
144 */
145 protected function createTrueTypeFontDpiTestImage() {
146 $parseTimeStart = GeneralUtility::milliseconds();
147
148 $image = @imagecreate(200, 50);
149 imagecolorallocate($image, 255, 255, 55);
150 $textColor = imagecolorallocate($image, 233, 14, 91);
151 @imagettftext(
152 $image,
153 GeneralUtility::freetypeDpiComp(20),
154 0,
155 10,
156 20,
157 $textColor,
158 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Private/Font/vera.ttf',
159 'Testing true type'
160 );
161 $outputFile = PATH_site . 'typo3temp/installTool-' . uniqid('createTrueTypeFontDpiTestImage') . '.gif';
162 imagegif($image, $outputFile);
163
164 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
165 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
166 $message->setTitle('True type font DPI settings');
167 $message->setMessage(
168 'If the two images below do not look the same, set $TYPO3_CONF_VARS[GFX][TTFdpi] to a value of 72.'
169 );
170
171 $testResults = array();
172 $testResults['ttf'] = array();
173 $testResults['ttf']['message'] = $message;
174 $testResults['ttf']['title'] = '';
175 $testResults['ttf']['outputFile'] = $outputFile;
176 $testResults['ttf']['referenceFile'] = $this->imageBasePath . 'TestReference/Font.gif';
177
178 $this->view->assign('testResults', $testResults);
179 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
180 }
181
182 /**
183 * Create jpg from various image formats using IM / GM
184 *
185 * @return \TYPO3\CMS\Install\Status\StatusInterface
186 */
187 protected function convertImageFormatsToJpg() {
188 $this->setUpDatabaseConnectionMock();
189 $imageProcessor = $this->initializeImageProcessor();
190 $parseTimeStart = GeneralUtility::milliseconds();
191
192 $inputFormatsToTest = array('jpg', 'gif', 'png', 'tif', 'bmp', 'pcx', 'tga', 'pdf', 'ai');
193
194 $testResults = array();
195 foreach ($inputFormatsToTest as $formatToTest) {
196 $result = array();
197 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $formatToTest)) {
198 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
199 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
200 $message->setTitle('Skipped test');
201 $message->setMessage('Handling format ' . $formatToTest . ' must be enabled in TYPO3_CONF_VARS[\'GFX\'][\'imagefile_ext\']');
202 $result['error'] = $message;
203 } else {
204 $imageProcessor->IM_commands = array();
205 $inputFile = $this->imageBasePath . 'TestInput/Test.' . $formatToTest;
206 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('read') . '-' . $formatToTest;
207 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'jpg', '170', '', '', '', array(), TRUE);
208 $result['title'] = 'Read ' . $formatToTest;
209 if ($imResult !== NULL) {
210 $result['outputFile'] = $imResult[3];
211 $result['referenceFile'] = $this->imageBasePath . 'TestReference/Read-' . $formatToTest . '.jpg';
212 $result['command'] = $imageProcessor->IM_commands;
213 } else {
214 $result['error'] = $this->imageGenerationFailedMessage();
215 }
216
217 }
218 $testResults[] = $result;
219 }
220
221 $this->view->assign('testResults', $testResults);
222 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
223 }
224
225 /**
226 * Write gif and png test
227 *
228 * @return \TYPO3\CMS\Install\Status\StatusInterface
229 */
230 protected function writeGifAndPng() {
231 $this->setUpDatabaseConnectionMock();
232 $imageProcessor = $this->initializeImageProcessor();
233 $parseTimeStart = GeneralUtility::milliseconds();
234
235 $testResults = array(
236 'gif' => array(),
237 'png' => array(),
238 );
239
240 // Gif
241 $inputFile = $this->imageBasePath . 'TestInput/Test.gif';
242 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('write-gif');
243 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'gif', '', '', '', '', array(), TRUE);
244 if ($imResult !== NULL && is_file($imResult[3])) {
245 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress']) {
246 clearstatcache();
247 $previousSize = GeneralUtility::formatSize(filesize($imResult[3]));
248 $methodUsed = GeneralUtility::gif_compress($imResult[3], '');
249 clearstatcache();
250 $compressedSize = GeneralUtility::formatSize(filesize($imResult[3]));
251 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
252 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
253 $message->setTitle('Compressed gif');
254 $message->setMessage(
255 'Method used by compress: ' . $methodUsed . LF
256 . ' Previous filesize: ' . $previousSize . '. Current filesize:' . $compressedSize
257 );
258 } else {
259 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
260 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
261 $message->setTitle('Gif compression not enabled by [GFX][gif_compress]');
262 }
263 $testResults['gif']['message'] = $message;
264 $testResults['gif']['title'] = 'Write gif';
265 $testResults['gif']['outputFile'] = $imResult[3];
266 $testResults['gif']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-gif.gif';
267 $testResults['gif']['command'] = $imageProcessor->IM_commands;
268 } else {
269 $testResults['gif']['error'] = $this->imageGenerationFailedMessage();
270 }
271
272 // Png
273 $inputFile = $this->imageBasePath . 'TestInput/Test.png';
274 $imageProcessor->IM_commands = array();
275 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('write-png');
276 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'png', '', '', '', '', array(), TRUE);
277 if ($imResult !== NULL) {
278 $testResults['png']['title'] = 'Write png';
279 $testResults['png']['outputFile'] = $imResult[3];
280 $testResults['png']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-png.png';
281 $testResults['png']['command'] = $imageProcessor->IM_commands;
282 } else {
283 $testResults['png']['error'] = $this->imageGenerationFailedMessage();
284 }
285
286 $this->view->assign('testResults', $testResults);
287 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
288 }
289
290 /**
291 * Write gif and png test
292 *
293 * @return \TYPO3\CMS\Install\Status\StatusInterface
294 */
295 protected function scaleImages() {
296 $this->setUpDatabaseConnectionMock();
297 $imageProcessor = $this->initializeImageProcessor();
298 $parseTimeStart = GeneralUtility::milliseconds();
299
300 $testResults = array(
301 'gif-to-gif' => array(),
302 'png-to-png' => array(),
303 'gif-to-jpg' => array(),
304 );
305
306 $imageProcessor->IM_commands = array();
307 $inputFile = $this->imageBasePath . 'TestInput/Transparent.gif';
308 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('scale-gif');
309 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'gif', '150', '', '', '', array(), TRUE);
310 if ($imResult !== NULL) {
311 $testResults['gif-to-gif']['title'] = 'gif to gif';
312 $testResults['gif-to-gif']['outputFile'] = $imResult[3];
313 $testResults['gif-to-gif']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-gif.gif';
314 $testResults['gif-to-gif']['command'] = $imageProcessor->IM_commands;
315 } else {
316 $testResults['gif-to-gif']['error'] = $this->imageGenerationFailedMessage();
317 }
318
319 $imageProcessor->IM_commands = array();
320 $inputFile = $this->imageBasePath . 'TestInput/Transparent.png';
321 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('scale-png');
322 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'png', '150', '', '', '', array(), TRUE);
323 if ($imResult !== NULL) {
324 $testResults['png-to-png']['title'] = 'png to png';
325 $testResults['png-to-png']['outputFile'] = $imResult[3];
326 $testResults['png-to-png']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-png.png';
327 $testResults['png-to-png']['command'] = $imageProcessor->IM_commands;
328 } else {
329 $testResults['png-to-png']['error'] = $this->imageGenerationFailedMessage();
330 }
331
332 $imageProcessor->IM_commands = array();
333 $inputFile = $this->imageBasePath . 'TestInput/Transparent.gif';
334 $imageProcessor->imageMagickConvert_forceFileNameBody = uniqid('scale-jpg');
335 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'jpg', '150', '', '', '', array(), TRUE);
336 if ($imResult !== NULL) {
337 $testResults['gif-to-jpg']['title'] = 'gif to jpg';
338 $testResults['gif-to-jpg']['outputFile'] = $imResult[3];
339 $testResults['gif-to-jpg']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-jpg.jpg';
340 $testResults['gif-to-jpg']['command'] = $imageProcessor->IM_commands;
341 } else {
342 $testResults['gif-to-jpg']['error'] = $this->imageGenerationFailedMessage();
343 }
344
345 $this->view->assign('testResults', $testResults);
346 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
347 }
348
349 /**
350 * Combine multiple images into one test
351 *
352 * @return \TYPO3\CMS\Install\Status\StatusInterface
353 */
354 protected function combineImages() {
355 $this->setUpDatabaseConnectionMock();
356 $imageProcessor = $this->initializeImageProcessor();
357 $parseTimeStart = GeneralUtility::milliseconds();
358
359 $testResults = array(
360 'combine1' => array(),
361 'combine2' => array(),
362 );
363
364 $inputFile = $this->imageBasePath . 'TestInput/BackgroundGreen.gif';
365 $overlayFile = $this->imageBasePath . 'TestInput/Test.jpg';
366 $maskFile = $this->imageBasePath . 'TestInput/MaskBlackWhite.gif';
367 $resultFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
368 . uniqid($imageProcessor->alternativeOutputKey . 'combine1') . '.jpg';
369 $imageProcessor->combineExec($inputFile, $overlayFile, $maskFile, $resultFile, TRUE);
370 $result = $imageProcessor->getImageDimensions($resultFile);
371 if ($result) {
372 $testResults['combine1']['title'] = 'Combine using a GIF mask with only black and white';
373 $testResults['combine1']['outputFile'] = $result[3];
374 $testResults['combine1']['referenceFile'] = $this->imageBasePath . 'TestReference/Combine-1.jpg';
375 $testResults['combine1']['command'] = $imageProcessor->IM_commands;
376 } else {
377 $testResults['combine1']['error'] = $this->imageGenerationFailedMessage();
378 }
379
380 $imageProcessor->IM_commands = array();
381 $inputFile = $this->imageBasePath . 'TestInput/BackgroundCombine.jpg';
382 $overlayFile = $this->imageBasePath . 'TestInput/Test.jpg';
383 $maskFile = $this->imageBasePath . 'TestInput/MaskCombine.jpg';
384 $resultFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
385 . uniqid($imageProcessor->alternativeOutputKey . 'combine2') . '.jpg';
386 $imageProcessor->combineExec($inputFile, $overlayFile, $maskFile, $resultFile, TRUE);
387 $result = $imageProcessor->getImageDimensions($resultFile);
388 if ($result) {
389 $testResults['combine2']['title'] = 'Combine using a JPG mask with graylevels';
390 $testResults['combine2']['outputFile'] = $result[3];
391 $testResults['combine2']['referenceFile'] = $this->imageBasePath . 'TestReference/Combine-2.jpg';
392 $testResults['combine2']['command'] = $imageProcessor->IM_commands;
393 } else {
394 $testResults['combine2']['error'] = $this->imageGenerationFailedMessage();
395 }
396
397 $this->view->assign('testResults', $testResults);
398 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
399 }
400
401 /**
402 * Test gdlib functions
403 *
404 * @return \TYPO3\CMS\Install\Status\StatusInterface
405 */
406 protected function gdlib() {
407 $this->setUpDatabaseConnectionMock();
408 $imageProcessor = $this->initializeImageProcessor();
409 $parseTimeStart = GeneralUtility::milliseconds();
410 $gifOrPng = $imageProcessor->gifExtension;
411 $testResults = array();
412
413 // GD with simple box
414 $imageProcessor->IM_commands = array();
415 $image = imagecreatetruecolor(170, 136);
416 $backgroundColor = imagecolorallocate($image, 0, 0, 0);
417 imagefilledrectangle($image, 0, 0, 170, 136, $backgroundColor);
418 $workArea = array(0, 0, 170, 136);
419 $conf = array(
420 'dimensions' => '10,50,150,36',
421 'color' => 'olive',
422 );
423 $imageProcessor->makeBox($image, $conf, $workArea);
424 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . uniqid('gdSimple') . '.' . $gifOrPng;
425 $imageProcessor->ImageWrite($image, $outputFile);
426 $result = $imageProcessor->getImageDimensions($outputFile);
427 $testResults['simple'] = array();
428 $testResults['simple']['title'] = 'Create simple image';
429 $testResults['simple']['outputFile'] = $result[3];
430 $testResults['simple']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-simple.' . $gifOrPng;
431
432 // GD from image with box
433 $imageProcessor->IM_commands = array();
434 $inputFile = $this->imageBasePath . 'TestInput/Test.' . $gifOrPng;
435 $image = $imageProcessor->imageCreateFromFile($inputFile);
436 $workArea = array(0, 0, 170, 136);
437 $conf = array(
438 'dimensions' => '10,50,150,36',
439 'color' => 'olive',
440 );
441 $imageProcessor->makeBox($image, $conf, $workArea);
442 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . uniqid('gdBox') . '.' . $gifOrPng;
443 $imageProcessor->ImageWrite($image, $outputFile);
444 $result = $imageProcessor->getImageDimensions($outputFile);
445 $testResults['box'] = array();
446 $testResults['box']['title'] = 'Create image from file';
447 $testResults['box']['outputFile'] = $result[3];
448 $testResults['box']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-box.' . $gifOrPng;
449
450 // GD with text
451 $imageProcessor->IM_commands = array();
452 $image = imagecreatetruecolor(170, 136);
453 $backgroundColor = imagecolorallocate($image, 128, 128, 150);
454 imagefilledrectangle($image, 0, 0, 170, 136, $backgroundColor);
455 $workArea = array(0, 0, 170, 136);
456 $conf = array(
457 'iterations' => 1,
458 'angle' => 0,
459 'antiAlias' => 1,
460 'text' => 'HELLO WORLD',
461 'fontColor' => '#003366',
462 'fontSize' => 18,
463 'fontFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Private/Font/vera.ttf',
464 'offset' => '17,40',
465 );
466 $conf['BBOX'] = $imageProcessor->calcBBox($conf);
467 $imageProcessor->makeText($image, $conf, $workArea);
468 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . uniqid('gdText') . '.' . $gifOrPng;
469 $imageProcessor->ImageWrite($image, $outputFile);
470 $result = $imageProcessor->getImageDimensions($outputFile);
471 $testResults['text'] = array();
472 $testResults['text']['title'] = 'Render text with TrueType font';
473 $testResults['text']['outputFile'] = $result[3];
474 $testResults['text']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-text.' . $gifOrPng;
475
476 // GD with text, niceText
477 $testResults['niceText'] = array();
478 if ($this->isImageMagickEnabledAndConfigured()) {
479 // Warning: Re-uses $conf from above!
480 $conf['offset'] = '17,65';
481 $conf['niceText'] = 1;
482 $imageProcessor->makeText($image, $conf, $workArea);
483 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . uniqid('gdNiceText') . '.' . $gifOrPng;
484 $imageProcessor->ImageWrite($image, $outputFile);
485 $result = $imageProcessor->getImageDimensions($outputFile);
486 $testResults['niceText']['title'] = 'Render text with TrueType font using \'niceText\' option';
487 $testResults['niceText']['outputFile'] = $result[3];
488 $testResults['niceText']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-niceText.' . $gifOrPng;
489 $testResults['niceText']['commands'] = $imageProcessor->IM_commands;
490 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
491 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
492 $message->setTitle('Note on \'niceText\'');
493 $message->setMessage(
494 '\'niceText\' is a concept that tries to improve the antialiasing of the rendered type by'
495 . ' actually rendering the textstring in double size on a black/white mask, downscaling the mask'
496 . ' and masking the text onto the image through this mask. This involves'
497 . ' ImageMagick \'combine\'/\'composite\' and \'convert\'.'
498 );
499 $testResults['niceText']['message'] = $message;
500 } else {
501 $result['niceText']['error'] = $this->imageGenerationFailedMessage();
502 }
503
504 // GD with text, niceText, shadow
505 $testResults['shadow'] = array();
506 if ($this->isImageMagickEnabledAndConfigured()) {
507 // Warning: Re-uses $conf from above!
508 $conf['offset'] = '17,90';
509 $conf['niceText'] = 1;
510 $conf['shadow.'] = array(
511 'offset' => '2,2',
512 'blur' => $imageProcessor->V5_EFFECTS ? '20' : '90',
513 'opacity' => '50',
514 'color' => 'black'
515 );
516 // Warning: Re-uses $image from above!
517 $imageProcessor->makeShadow($image, $conf['shadow.'], $workArea, $conf);
518 $imageProcessor->makeText($image, $conf, $workArea);
519 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . uniqid('GDwithText-niceText-shadow') . '.' . $gifOrPng;
520 $imageProcessor->ImageWrite($image, $outputFile);
521 $result = $imageProcessor->getImageDimensions($outputFile);
522 $testResults['shadow']['title'] = 'Render \'niceText\' with a shadow under';
523 $testResults['shadow']['outputFile'] = $result[3];
524 $testResults['shadow']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-shadow.' . $gifOrPng;
525 $testResults['shadow']['commands'] = $imageProcessor->IM_commands;
526 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
527 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
528 $message->setTitle('Note on \'shadow\'');
529 $message->setMessage(
530 'This test makes sense only if the above test had a correct output. But if so, you may not see'
531 . ' a soft dropshadow from the third text string as you should. In that case you are most likely'
532 . ' using ImageMagick 5 and should set the flag TYPO3_CONF_VARS[GFX][im_v5effects].'
533 );
534 $testResults['shadow']['message'] = $message;
535 } else {
536 $result['shadow']['error'] = $this->imageGenerationFailedMessage();
537 }
538
539 $this->view->assign('testResults', $testResults);
540 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
541 }
542
543 /**
544 * Create a 'image test was done' message
545 *
546 * @param integer $parseTime Parse time
547 * @return \TYPO3\CMS\Install\Status\StatusInterface
548 */
549 protected function imageTestDoneMessage($parseTime = 0) {
550 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
551 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
552 $message->setTitle('Executed image tests');
553 $message->setMessage('Parse time: ' . $parseTime . ' ms');
554 return $message;
555 }
556
557 /**
558 * Create a 'imageMagick disabled' message
559 *
560 * @return \TYPO3\CMS\Install\Status\StatusInterface
561 */
562 protected function imageMagickDisabledMessage() {
563 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
564 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
565 $message->setTitle('Tests not executed');
566 $message->setMessage('ImageMagick / GraphicsMagick handling is disabled or not configured correctly.');
567 return $message;
568 }
569
570 /**
571 * Create a 'image generation failed' message
572 *
573 * @return \TYPO3\CMS\Install\Status\StatusInterface
574 */
575 protected function imageGenerationFailedMessage() {
576 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
577 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
578 $message->setTitle('Image generation failed');
579 $message->setMessage(
580 'ImageMagick / GraphicsMagick handling is enabled, but the execute'
581 . ' command returned an error. Please check your settings, especially'
582 . ' [\'GFX\'][\'im_path\'] and [\'GFX\'][\'im_path_lzw\'].'
583 );
584 return $message;
585 }
586
587 /**
588 * Gather image configuration overview
589 *
590 * @return array Result array
591 */
592 protected function getImageConfiguration() {
593 $result = array();
594 $result['imageMagickOrGraphicsMagick'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm' ? 'gm' : 'im';
595 $result['imageMagickEnabled'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'];
596 $result['imageMagickPath'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'];
597 $result['imageMagickVersion'] = $this->determineImageMagickVersion();
598 $result['imageMagick5Effects'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'];
599 $result['gdlibEnabled'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'];
600 $result['gdlibPng'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'];
601 $result['freeTypeDpi'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi'];
602 $result['fileFormats'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
603 return $result;
604 }
605
606 /**
607 * Initialize image processor
608 *
609 * @return \TYPO3\CMS\Core\Imaging\GraphicalFunctions Initialized image processor
610 */
611 protected function initializeImageProcessor() {
612 /** @var \TYPO3\CMS\Core\Imaging\GraphicalFunctions $imageProcessor */
613 $imageProcessor = $this->objectManager->get('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
614 $imageProcessor->init();
615 $imageProcessor->tempPath = PATH_site . 'typo3temp/';
616 $imageProcessor->dontCheckForExistingTempFile = 1;
617 $imageProcessor->enable_typo3temp_db_tracking = 0;
618 $imageProcessor->filenamePrefix = 'installTool-';
619 $imageProcessor->dontCompress = 1;
620 $imageProcessor->alternativeOutputKey = 'typo3InstallTest';
621 $imageProcessor->noFramePrepended = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noFramePrepended'];
622 return $imageProcessor;
623 }
624
625 /**
626 * Find out if ImageMagick or GraphicsMagick is enabled and set up
627 *
628 * @return boolean TRUE if enabled and path is set
629 */
630 protected function isImageMagickEnabledAndConfigured() {
631 $enabled = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'];
632 $path = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'];
633 return $enabled && $path;
634 }
635
636 /**
637 * Determine ImageMagick / GraphicsMagick version
638 *
639 * @return string Version
640 */
641 protected function determineImageMagickVersion() {
642 $command = \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand('identify', '-version');
643 \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $result);
644 $string = $result[0];
645 list(, $version) = explode('Magick', $string);
646 list($version) = explode(' ', trim($version));
647 return trim($version);
648 }
649
650 /**
651 * Instantiate a dummy instance for $GLOBALS['TYPO3_DB'] to
652 * prevent real database calls
653 *
654 * @return void
655 */
656 protected function setUpDatabaseConnectionMock() {
657 $database = $this->objectManager->get('TYPO3\\CMS\\Install\\Database\\DatabaseConnectionMock');
658 $GLOBALS['TYPO3_DB'] = $database;
659 }
660 }