ImageMagick6Preset.php 3.23 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 ImageMagick version 6 or higher
23
 * @internal only to be used within EXT:install
24
 */
25
class ImageMagick6Preset extends AbstractImagePreset
26
27
28
29
30
{
    /**
     * @var string Name of preset
     */
    protected $name = 'ImageMagick6';
31

32
33
34
35
    /**
     * @var int Priority of preset
     */
    protected $priority = 70;
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' => 'ImageMagick',
45
        'GFX/processor_effects' => true,
46
47
        'GFX/processor_allowTemporaryMasksAsPng' => false,
        'GFX/processor_colorspace' => 'sRGB',
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->findImageMagick6InPaths($searchPaths);
    }
60

61
62
63
64
65
66
67
68
69
70
    /**
     * Search for GraphicsMagick executables in given paths.
     *
     * @param array $searchPaths List of paths to search for
     * @return bool TRUE if graphics magick was found in path
     */
    protected function findImageMagick6InPaths(array $searchPaths)
    {
        $result = false;
        foreach ($searchPaths as $path) {
71
            if (Environment::isWindows()) {
72
                $executable = 'identify.exe';
73
74
75
76

                if (!@is_file($path . $executable)) {
                    $executable = 'magick.exe';
                }
77
78
79
80
81
            } else {
                $executable = 'identify';
            }
            if (@is_file($path . $executable)) {
                $command = escapeshellarg($path . $executable) . ' -version';
82
                $executingResult = [];
83
                CommandUtility::exec($command, $executingResult);
84
85
86
                // First line of exec command should contain string GraphicsMagick
                $firstResultLine = array_shift($executingResult);
                // Example: "Version: ImageMagick 6.6.0-4 2012-05-02 Q16 http://www.imagemagick.org"
87
                if (str_contains($firstResultLine, 'ImageMagick')) {
88
                    [, $version] = explode('ImageMagick', $firstResultLine);
89
                    // Example: "6.6.0-4"
90
                    [$version] = explode(' ', trim($version));
91
92
93
94
95
96
97
98
99
100
                    if (version_compare($version, '6.0.0') >= 0) {
                        $this->foundPath = $path;
                        $result = true;
                        break;
                    }
                }
            }
        }
        return $result;
    }
101
}