GraphicsMagickPreset.php 2.72 KB
Newer Older
1
<?php
2

3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
7
8
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
9
 *
10
11
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
14
 * The TYPO3 project - inspiring people to share!
 */
15

16
17
namespace TYPO3\CMS\Install\Configuration\Image;

18
use TYPO3\CMS\Core\Core\Environment;
19
use TYPO3\CMS\Core\Utility\CommandUtility;
20

21
22
/**
 * Preset for GraphicsMagick
23
 * @internal only to be used within EXT:install
24
 */
25
class GraphicsMagickPreset extends AbstractImagePreset
26
27
28
29
30
{
    /**
     * @var string Name of preset
     */
    protected $name = 'GraphicsMagick';
31

32
33
34
35
    /**
     * @var int Priority of preset
     */
    protected $priority = 80;
36

37
38
39
    /**
     * @var array Configuration values handled by this preset
     */
40
    protected $configurationValues = [
41
        'GFX/processor_enabled' => true,
42
        // processor_path is determined and set by path lookup methods
43
44
        'GFX/processor_path' => '',
        'GFX/processor' => 'GraphicsMagick',
45
        'GFX/processor_effects' => false,
46
47
        'GFX/processor_allowTemporaryMasksAsPng' => false,
        'GFX/processor_colorspace' => 'RGB',
48
    ];
49

50
51
52
53
54
55
56
57
58
59
    /**
     * Find executable in path, wrapper for specific ImageMagick/GraphicsMagick find methods.
     *
     * @param array $searchPaths
     * @return mixed
     */
    protected function findExecutableInPath(array $searchPaths)
    {
        return $this->findGraphicsMagickInPaths($searchPaths);
    }
60

61
62
63
    /**
     * Search for GraphicsMagick executables in given paths.
     *
64
     * @param array $searchPaths List of paths to search for
65
66
67
68
69
70
     * @return bool TRUE if graphics magick was found in path
     */
    protected function findGraphicsMagickInPaths(array $searchPaths)
    {
        $result = false;
        foreach ($searchPaths as $path) {
71
            if (Environment::isWindows()) {
72
73
74
75
76
77
                $executable = 'gm.exe';
            } else {
                $executable = 'gm';
            }
            if (@is_file($path . $executable)) {
                $command = escapeshellarg($path . $executable) . ' -version';
78
                $executingResult = [];
79
                CommandUtility::exec($command, $executingResult);
80
81
                // First line of exec command should contain string GraphicsMagick
                $firstResultLine = array_shift($executingResult);
82
                if (str_contains($firstResultLine, 'GraphicsMagick')) {
83
84
85
86
87
88
89
90
                    $this->foundPath = $path;
                    $result = true;
                    break;
                }
            }
        }
        return $result;
    }
91
}