public function optimizeThumbnail(JoinPointInterface $joinPoint)
    {
        /** @var \Neos\Media\Domain\Model\Thumbnail $thumbnail */
        $thumbnail = $joinPoint->getProxy();
        $thumbnailResource = $thumbnail->getResource();
        if (!$thumbnailResource) {
            return;
        }

        $streamMetaData = stream_get_meta_data($thumbnailResource->getStream());
        $pathAndFilename = $streamMetaData['uri'];

        $useGlobalBinary = $this->settings['useGlobalBinary'];
        $binaryRootPath = 'Private/Library/node_modules/';
        $file = escapeshellarg($pathAndFilename);
        $imageType = $thumbnailResource->getMediaType();

        if (!array_key_exists($imageType, $this->settings['formats'])) {
            $this->systemLogger->log(sprintf('Unsupported type "%s" skipped in optimizeThumbnail', $imageType), LOG_INFO);
            return;
        }

        $librarySettings = $this->settings['formats'][$imageType];

        if ($librarySettings['enabled'] === false) {
            return;
        }

        if ($librarySettings['useGlobalBinary'] === true) {
            $useGlobalBinary = true;
        }

        $library = $librarySettings['library'];
        $binaryPath = $librarySettings['binaryPath'];
        $eelExpression = $librarySettings['arguments'];
        $parameters = array_merge($librarySettings['parameters'], ['file' => $file]);
        $arguments = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, $parameters);

        $binaryPath = $useGlobalBinary === true ? $this->settings['globalBinaryPath'] . $library : $this->packageManager->getPackage('MOC.ImageOptimizer')->getResourcesPath() . $binaryRootPath . $binaryPath;
        $cmd = escapeshellcmd($binaryPath) . ' ' . $arguments;
        $output = [];
        exec($cmd, $output, $result);
        $failed = (int)$result !== 0;
        $this->systemLogger->log($cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', $failed ? LOG_ERR : LOG_INFO, $output);
    }