• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.75
/Classes/ViewHelpers/Media/PdfThumbnailViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use TYPO3\CMS\Core\Utility\CommandUtility;
12
use TYPO3\CMS\Core\Utility\GeneralUtility;
13

14
/**
15
 * Converts the provided PDF file into a PNG thumbnail and renders
16
 * the according image tag using Fluid's standard image ViewHelper
17
 * thus implementing its arguments. For PDF documents with multiple
18
 * pages the first page is rendered by default unless specified.
19
 */
20
class PdfThumbnailViewHelper extends ImageViewHelper
21
{
22
    public function initializeArguments(): void
23
    {
24
        parent::initializeArguments();
3✔
25
        $this->registerArgument('path', 'string', 'DEPRECATED: Use src instead');
3✔
26
        $this->registerArgument('minWidth', 'integer', 'DEPRECATED: Use minW instead');
3✔
27
        $this->registerArgument('minHeight', 'integer', 'DEPRECATED: Use minH instead');
3✔
28
        $this->registerArgument('maxWidth', 'integer', 'DEPRECATED: Use maxW instead');
3✔
29
        $this->registerArgument('maxHeight', 'integer', 'DEPRECATED: Use maxH instead');
3✔
30
        $this->registerArgument(
3✔
31
            'density',
3✔
32
            'integer',
3✔
33
            'Canvas resolution for rendering the PDF in dpi (higher means better quality)',
3✔
34
            false,
3✔
35
            100
3✔
36
        );
3✔
37
        $this->registerArgument(
3✔
38
            'background',
3✔
39
            'string',
3✔
40
            'Fill background of resulting image with this color (for transparent source files)'
3✔
41
        );
3✔
42
        $this->registerArgument(
3✔
43
            'rotate',
3✔
44
            'integer',
3✔
45
            'Number of degress to rotate resulting image by (caution: very slow if not multiple of 90)',
3✔
46
            false,
3✔
47
            0
3✔
48
        );
3✔
49
        $this->registerArgument(
3✔
50
            'page',
3✔
51
            'integer',
3✔
52
            'Optional page number to render as thumbnail for PDF documents with multiple pages',
3✔
53
            false,
3✔
54
            1
3✔
55
        );
3✔
56
        $this->registerArgument(
3✔
57
            'forceOverwrite',
3✔
58
            'boolean',
3✔
59
            'Forcibly overwrite existing converted PDF files',
3✔
60
            false,
3✔
61
            false
3✔
62
        );
3✔
63
    }
64

65
    public function render(): string
66
    {
67
        /** @var string $srcArgument */
68
        $srcArgument = $this->arguments['src'];
×
69
        $src = GeneralUtility::getFileAbsFileName($srcArgument);
×
70
        if (!file_exists($src)) {
×
71
            return '';
×
72
        }
73
        /** @var int $density */
74
        $density = $this->arguments['density'];
×
75
        /** @var int $rotate */
76
        $rotate = $this->arguments['rotate'];
×
77
        /** @var int $page */
78
        $page = $this->arguments['page'];
×
79
        /** @var string|null $background */
80
        $background = $this->arguments['background'];
×
81
        $forceOverwrite = (bool) $this->arguments['forceOverwrite'];
×
82
        $filename = basename($src);
×
83
        $pageArgument = $page > 0 ? $page - 1 : 0;
×
84
        if (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_colorspace'])) {
×
85
            $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_colorspace'];
×
86
        } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'])) {
×
87
            $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'];
×
88
        } else {
89
            $colorspace = 'RGB';
×
90
        }
91
        $tempPath = 'typo3temp/assets/';
×
92
        $path = GeneralUtility::getFileAbsFileName(
×
93
            $tempPath
×
94
            . 'vhs-pdf-'
×
95
            . pathinfo($filename, PATHINFO_FILENAME)
×
96
            . '-'
×
97
            . $page
×
98
            . '-'
×
99
            . filemtime($src)
×
100
            . '.png'
×
101
        );
×
102
        if (!file_exists($path) || $forceOverwrite) {
×
103
            $arguments = '-colorspace ' . $colorspace;
×
104
            if (0 < (int) $density) {
×
105
                $arguments .= ' -density ' . $density;
×
106
            }
107
            if (0 !== (int) $rotate) {
×
108
                $arguments .= ' -rotate ' . $rotate;
×
109
            }
110
            $arguments .= ' "' . $src . '"[' . $pageArgument . ']';
×
111
            if (null !== $background) {
×
112
                $arguments .= ' -background "' . $background . '" -flatten';
×
113
            }
114
            $arguments .= ' "' . $path . '"';
×
115
            $command = CommandUtility::imageMagickCommand('convert', $arguments);
×
116
            CommandUtility::exec($command);
×
117
        }
118
        $this->preprocessImage($path);
×
119
        return $this->renderTag();
×
120
    }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc