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