[TASK] Replace TYPO3_OS constant with Environment check
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / Image / GraphicsMagickPreset.php
1 <?php
2 namespace TYPO3\CMS\Install\Configuration\Image;
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\Core\Core\Environment;
18
19 /**
20 * Preset for GraphicsMagick
21 */
22 class GraphicsMagickPreset extends AbstractImagePreset
23 {
24 /**
25 * @var string Name of preset
26 */
27 protected $name = 'GraphicsMagick';
28
29 /**
30 * @var int Priority of preset
31 */
32 protected $priority = 80;
33
34 /**
35 * @var array Configuration values handled by this preset
36 */
37 protected $configurationValues = [
38 'GFX/processor_enabled' => true,
39 // processor_path and processor_path_lzw are determined and set by path lookup methods
40 'GFX/processor_path' => '',
41 'GFX/processor_path_lzw' => '',
42 'GFX/processor' => 'GraphicsMagick',
43 'GFX/processor_effects' => -1,
44 'GFX/processor_allowTemporaryMasksAsPng' => false,
45 'GFX/processor_colorspace' => 'RGB',
46 ];
47
48 /**
49 * Find executable in path, wrapper for specific ImageMagick/GraphicsMagick find methods.
50 *
51 * @param array $searchPaths
52 * @return mixed
53 */
54 protected function findExecutableInPath(array $searchPaths)
55 {
56 return $this->findGraphicsMagickInPaths($searchPaths);
57 }
58
59 /**
60 * Search for GraphicsMagick executables in given paths.
61 *
62 * @param array $searchPaths List of paths to search for
63 * @return bool TRUE if graphics magick was found in path
64 */
65 protected function findGraphicsMagickInPaths(array $searchPaths)
66 {
67 $result = false;
68 foreach ($searchPaths as $path) {
69 if (Environment::isWindows()) {
70 $executable = 'gm.exe';
71 } else {
72 $executable = 'gm';
73 }
74 if (@is_file($path . $executable)) {
75 $command = escapeshellarg($path . $executable) . ' -version';
76 $executingResult = false;
77 \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $executingResult);
78 // First line of exec command should contain string GraphicsMagick
79 $firstResultLine = array_shift($executingResult);
80 if (strpos($firstResultLine, 'GraphicsMagick') !== false) {
81 $this->foundPath = $path;
82 $result = true;
83 break;
84 }
85 }
86 }
87 return $result;
88 }
89 }