Skip to content

Commit 5e1107b

Browse files
committed
use image processing for testing IPTC preservation
1 parent be81eb3 commit 5e1107b

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace WapplerSystems\ZabbixClient\Imaging;
4+
5+
use TYPO3\CMS\Core\Imaging\ImageMagickFile;
6+
use TYPO3\CMS\Core\Utility\CommandUtility;
7+
8+
class GraphicalFunctions extends \TYPO3\CMS\Core\Imaging\GraphicalFunctions
9+
{
10+
11+
12+
public function imageMagickMetadata($imagefile): ?array
13+
{
14+
if (!$this->processorEnabled) {
15+
return null;
16+
}
17+
18+
$result = $this->executeFullIdentifyCommandForImageFile($imagefile);
19+
if ($result) {
20+
return $result;
21+
}
22+
return null;
23+
}
24+
25+
26+
protected function executeFullIdentifyCommandForImageFile(string $imageFile): ?array
27+
{
28+
$frame = $this->addFrameSelection ? 0 : null;
29+
$cmd = CommandUtility::imageMagickCommand(
30+
'identify',
31+
'-verbose ' . ImageMagickFile::fromFilePath($imageFile, $frame)
32+
);
33+
$returnVal = [];
34+
CommandUtility::exec($cmd, $returnVal);
35+
$this->IM_commands[] = ['identify', $cmd, implode(',', $returnVal)];
36+
return $returnVal;
37+
}
38+
39+
}

Classes/Operation/HasIPTCPreservation.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
* LICENSE.txt file that was distributed with this source code.
1010
*/
1111

12-
use TYPO3\CMS\Core\Configuration\Features;
1312
use TYPO3\CMS\Core\SingletonInterface;
13+
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
1414
use TYPO3\CMS\Core\Utility\GeneralUtility;
15+
use TYPO3\CMS\Core\Utility\StringUtility;
1516
use WapplerSystems\ZabbixClient\Attribute\MonitoringOperation;
17+
use WapplerSystems\ZabbixClient\Imaging\GraphicalFunctions;
1618
use WapplerSystems\ZabbixClient\OperationResult;
1719

1820

@@ -32,9 +34,38 @@ class HasIPTCPreservation implements IOperation, SingletonInterface
3234
*/
3335
public function execute(array $parameter = []): OperationResult
3436
{
35-
if (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_stripColorProfileParameters'])) {
36-
return new OperationResult(true, (bool)array_search('!iptc', $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_stripColorProfileParameters'] ?? []) !== false);
37+
$imageBasePath = ExtensionManagementUtility::extPath('zabbix_client') . 'Resources/Private/TestInput/';
38+
$imageProcessor = $this->initializeImageProcessor();
39+
$inputFile = $imageBasePath . 'TestIPTC.jpg';
40+
$imageProcessor->imageMagickConvert_forceFileNameBody = StringUtility::getUniqueId('iptc');
41+
$imResult = $imageProcessor->imageMagickConvert($inputFile, 'jpg', '200', '', '', '', [], true);
42+
if ($imResult !== null && file_exists($imResult[3])) {
43+
$metaData = $imageProcessor->imageMagickMetadata($imResult[3]);
44+
unlink($imResult[3]);
45+
foreach ($metaData as $value) {
46+
if (str_contains($value, 'Test-Image')) {
47+
return new OperationResult(true, true);
48+
}
49+
}
3750
}
38-
return new OperationResult(true, strpos($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_stripColorProfileCommand'] ?? '','!iptc') !== false);
51+
return new OperationResult(true, false);
3952
}
53+
54+
55+
/**
56+
* Initialize image processor
57+
*
58+
* @return GraphicalFunctions Initialized image processor
59+
*/
60+
protected function initializeImageProcessor(): GraphicalFunctions
61+
{
62+
$imageProcessor = GeneralUtility::makeInstance(GraphicalFunctions::class);
63+
$imageProcessor->dontCheckForExistingTempFile = true;
64+
$imageProcessor->filenamePrefix = 'zabbixClient-';
65+
$imageProcessor->dontCompress = true;
66+
$imageProcessor->alternativeOutputKey = 'zabbixClienTest';
67+
$imageProcessor->setImageFileExt(['gif', 'jpg', 'png', 'tif', 'ai', 'pdf', 'webp']);
68+
return $imageProcessor;
69+
}
70+
4071
}
34 KB
Loading

0 commit comments

Comments
 (0)