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