Skip to content

Commit 813fa5f

Browse files
Merge pull request #23 from move-elevator/feature/media-support-checks
feat: add AVIF, WebP and brotli support checks to requirements
2 parents ea4bac3 + dc6c143 commit 813fa5f

5 files changed

Lines changed: 143 additions & 1 deletion

File tree

autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
require_once(__DIR__ . '/deployer/requirements/task/check_locales.php');
4545
require_once(__DIR__ . '/deployer/requirements/task/check_packages.php');
4646
require_once(__DIR__ . '/deployer/requirements/task/check_image_processing.php');
47+
require_once(__DIR__ . '/deployer/requirements/task/check_media_support.php');
4748
require_once(__DIR__ . '/deployer/requirements/task/check_php_extensions.php');
4849
require_once(__DIR__ . '/deployer/requirements/task/check_php_settings.php');
4950
require_once(__DIR__ . '/deployer/requirements/task/check_database.php');

deployer/requirements/config/set.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
set('requirements_check_locales_enabled', true);
1212
set('requirements_check_packages_enabled', true);
1313
set('requirements_check_image_processing_enabled', true);
14+
set('requirements_check_media_support_enabled', true);
1415
set('requirements_check_php_extensions_enabled', true);
1516
set('requirements_check_php_settings_enabled', true);
1617
set('requirements_check_database_enabled', true);
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Deployer;
6+
7+
use Deployer\Exception\RunException;
8+
9+
task('requirements:check:media_support', function (): void {
10+
if (!get('requirements_check_media_support_enabled')) {
11+
return;
12+
}
13+
14+
checkGdFormatSupport();
15+
checkImageToolFormatSupport();
16+
checkBrotliExtension();
17+
})->hidden();
18+
19+
function checkGdFormatSupport(): void
20+
{
21+
$formats = ['AVIF' => 'AVIF Support', 'WebP' => 'WebP Support'];
22+
23+
try {
24+
$gdJson = run('php -r "echo function_exists(\'gd_info\') ? json_encode(gd_info()) : \'null\';" 2>/dev/null');
25+
} catch (RunException) {
26+
foreach ($formats as $label => $key) {
27+
addRequirementRow("GD: $label Support", REQUIREMENT_SKIP, 'Could not query GD');
28+
}
29+
30+
return;
31+
}
32+
33+
$gdInfo = json_decode($gdJson, true);
34+
35+
if (!is_array($gdInfo)) {
36+
foreach ($formats as $label => $key) {
37+
addRequirementRow("GD: $label Support", REQUIREMENT_SKIP, 'GD not available');
38+
}
39+
40+
return;
41+
}
42+
43+
foreach ($formats as $label => $key) {
44+
$supported = !empty($gdInfo[$key]);
45+
addRequirementRow(
46+
"GD: $label Support",
47+
$supported ? REQUIREMENT_OK : REQUIREMENT_WARN,
48+
$supported ? 'Supported' : 'Not compiled into GD'
49+
);
50+
}
51+
}
52+
53+
function checkImageToolFormatSupport(): void
54+
{
55+
$formats = ['AVIF' => 'AVIF', 'WEBP' => 'WebP'];
56+
$formatList = null;
57+
$toolLabel = null;
58+
59+
// Try GraphicsMagick first
60+
try {
61+
$output = run('gm convert -list format 2>/dev/null');
62+
63+
if ('' !== trim($output)) {
64+
$formatList = $output;
65+
$toolLabel = 'GraphicsMagick';
66+
}
67+
} catch (RunException) {
68+
// not available
69+
}
70+
71+
// Fallback to ImageMagick
72+
if (null === $formatList) {
73+
foreach (['magick', 'convert'] as $imCommand) {
74+
try {
75+
$output = run("$imCommand -list format 2>/dev/null");
76+
77+
if ('' !== trim($output)) {
78+
$formatList = $output;
79+
$toolLabel = 'ImageMagick';
80+
81+
break;
82+
}
83+
} catch (RunException) {
84+
continue;
85+
}
86+
}
87+
}
88+
89+
if (null === $formatList || null === $toolLabel) {
90+
foreach ($formats as $label) {
91+
addRequirementRow("IM/GM: $label", REQUIREMENT_SKIP, 'No image processing tool found');
92+
}
93+
94+
return;
95+
}
96+
97+
foreach ($formats as $formatKey => $label) {
98+
$supported = (bool) preg_match('/^\s*' . $formatKey . '\b/mi', $formatList);
99+
addRequirementRow(
100+
"IM/GM: $label",
101+
$supported ? REQUIREMENT_OK : REQUIREMENT_WARN,
102+
$supported ? "Supported ($toolLabel)" : "Format not supported ($toolLabel)"
103+
);
104+
}
105+
}
106+
107+
function checkBrotliExtension(): void
108+
{
109+
try {
110+
$modules = strtolower(run('php -m 2>/dev/null'));
111+
} catch (RunException) {
112+
addRequirementRow('PHP ext: brotli', REQUIREMENT_SKIP, 'Could not retrieve PHP modules');
113+
114+
return;
115+
}
116+
117+
$loaded = in_array('brotli', array_map('trim', explode("\n", $modules)), true);
118+
addRequirementRow(
119+
'PHP ext: brotli',
120+
$loaded ? REQUIREMENT_OK : REQUIREMENT_WARN,
121+
$loaded ? 'Loaded' : 'Not loaded'
122+
);
123+
}

deployer/requirements/task/requirements.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'requirements:check:locales',
99
'requirements:check:packages',
1010
'requirements:check:image_processing',
11+
'requirements:check:media_support',
1112
'requirements:check:php_extensions',
1213
'requirements:check:php_settings',
1314
'requirements:check:database',

docs/REQUIREMENTS.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ $ dep requirements:list [host]
2121
## Checks
2222

2323
### Locales
24-
2524
Verifies that required system locales are available (default: `de_DE.utf8`, `en_US.utf8`).
2625

2726
### System packages
@@ -32,6 +31,20 @@ Checks for required CLI tools: rsync, curl, ghostscript, git, gzip, mariadb-clie
3231

3332
Checks for GraphicsMagick (>= 1.3, recommended) or ImageMagick (>= 6.0) with version validation. Either one is sufficient.
3433

34+
### Media support
35+
36+
Checks for modern media format support across the PHP GD library and the installed image processing tool (GraphicsMagick or ImageMagick):
37+
38+
| Check | Method | OK | WARN | SKIP |
39+
|-------|--------|----|------|------|
40+
| GD: AVIF Support | `gd_info()` key `AVIF Support` | Supported | Not compiled into GD | GD not available |
41+
| GD: WebP Support | `gd_info()` key `WebP Support` | Supported | Not compiled into GD | GD not available |
42+
| IM/GM: AVIF | Format list (`-list format`) | Supported (tool name) | Format not supported (tool name) | No image processing tool found |
43+
| IM/GM: WebP | Format list (`-list format`) | Supported (tool name) | Format not supported (tool name) | No image processing tool found |
44+
| PHP ext: brotli | `php -m` | Loaded | Not loaded | Could not retrieve PHP modules |
45+
46+
All checks use WARN (not FAIL) since these features are recommended but not strictly required.
47+
3548
### PHP version
3649

3750
Validates the PHP version against the configured minimum (TYPO3: >= 8.2.0, default: >= 8.1.0).
@@ -158,6 +171,9 @@ set('requirements_packages', [
158171
set('requirements_mariadb_min_version', '10.6.0');
159172
set('requirements_mysql_min_version', '8.0.30');
160173

174+
// Disable media support checks (AVIF, WebP, brotli)
175+
set('requirements_check_media_support_enabled', false);
176+
161177
// Override image processing minimum versions
162178
set('requirements_graphicsmagick_min_version', '1.3.30');
163179
set('requirements_imagemagick_min_version', '7.0');

0 commit comments

Comments
 (0)