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

FluidTYPO3 / vhs / 25130651484

29 Apr 2026 07:55PM UTC coverage: 72.022%. Remained the same
25130651484

Pull #1968

github

web-flow
Merge 04fc0907a into 801f964d0
Pull Request #1968: [TASK] Replace non-canonical cast names (boolean) and (integer) with (bool) and (int)

100 of 129 new or added lines in 53 files covered. (77.52%)

5648 of 7842 relevant lines covered (72.02%)

19.99 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();
7✔
25
        $this->registerArgument('path', 'string', 'DEPRECATED: Use src instead');
7✔
26
        $this->registerArgument('minWidth', 'integer', 'DEPRECATED: Use minW instead');
7✔
27
        $this->registerArgument('minHeight', 'integer', 'DEPRECATED: Use minH instead');
7✔
28
        $this->registerArgument('maxWidth', 'integer', 'DEPRECATED: Use maxW instead');
7✔
29
        $this->registerArgument('maxHeight', 'integer', 'DEPRECATED: Use maxH instead');
7✔
30
        $this->registerArgument(
7✔
31
            'density',
7✔
32
            'integer',
7✔
33
            'Canvas resolution for rendering the PDF in dpi (higher means better quality)',
7✔
34
            false,
7✔
35
            100
7✔
36
        );
7✔
37
        $this->registerArgument(
7✔
38
            'background',
7✔
39
            'string',
7✔
40
            'Fill background of resulting image with this color (for transparent source files)'
7✔
41
        );
7✔
42
        $this->registerArgument(
7✔
43
            'rotate',
7✔
44
            'integer',
7✔
45
            'Number of degress to rotate resulting image by (caution: very slow if not multiple of 90)',
7✔
46
            false,
7✔
47
            0
7✔
48
        );
7✔
49
        $this->registerArgument(
7✔
50
            'page',
7✔
51
            'integer',
7✔
52
            'Optional page number to render as thumbnail for PDF documents with multiple pages',
7✔
53
            false,
7✔
54
            1
7✔
55
        );
7✔
56
        $this->registerArgument(
7✔
57
            'forceOverwrite',
7✔
58
            'boolean',
7✔
59
            'Forcibly overwrite existing converted PDF files',
7✔
60
            false,
7✔
61
            false
7✔
62
        );
7✔
63
    }
64

65
    /**
66
     * @return string
67
     */
68
    public function render()
69
    {
70
        /** @var string $srcArgument */
71
        $srcArgument = $this->arguments['src'];
×
72
        $src = GeneralUtility::getFileAbsFileName($srcArgument);
×
73
        if (!file_exists($src)) {
×
74
            return '';
×
75
        }
76
        /** @var int $density */
77
        $density = $this->arguments['density'];
×
78
        /** @var int $rotate */
79
        $rotate = $this->arguments['rotate'];
×
80
        /** @var int $page */
81
        $page = $this->arguments['page'];
×
82
        /** @var string|null $background */
83
        $background = $this->arguments['background'];
×
NEW
84
        $forceOverwrite = (bool) $this->arguments['forceOverwrite'];
×
85
        $filename = basename($src);
×
86
        $pageArgument = $page > 0 ? $page - 1 : 0;
×
87
        if (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_colorspace'])) {
×
88
            $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_colorspace'];
×
89
        } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'])) {
×
90
            $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'];
×
91
        } else {
92
            $colorspace = 'RGB';
×
93
        }
94
        $tempPath = 'typo3temp/assets/';
×
95
        $path = GeneralUtility::getFileAbsFileName(
×
96
            $tempPath
×
97
            . 'vhs-pdf-'
×
98
            . pathinfo($filename, PATHINFO_FILENAME)
×
99
            . '-'
×
100
            . $page
×
101
            . '-'
×
102
            . filemtime($src)
×
103
            . '.png'
×
104
        );
×
105
        if (!file_exists($path) || $forceOverwrite) {
×
106
            $arguments = '-colorspace ' . $colorspace;
×
NEW
107
            if (0 < (int) $density) {
×
108
                $arguments .= ' -density ' . $density;
×
109
            }
NEW
110
            if (0 !== (int) $rotate) {
×
111
                $arguments .= ' -rotate ' . $rotate;
×
112
            }
113
            $arguments .= ' "' . $src . '"[' . $pageArgument . ']';
×
114
            if (null !== $background) {
×
115
                $arguments .= ' -background "' . $background . '" -flatten';
×
116
            }
117
            $arguments .= ' "' . $path . '"';
×
118
            $command = CommandUtility::imageMagickCommand('convert', $arguments);
×
119
            CommandUtility::exec($command);
×
120
        }
121
        $this->preprocessImage($path);
×
122
        return $this->renderTag();
×
123
    }
124
}
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