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