• 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

55.56
/Classes/ViewHelpers/Media/ImageViewHelper.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 FluidTYPO3\Vhs\Traits\SourceSetViewHelperTrait;
12
use FluidTYPO3\Vhs\ViewHelpers\Media\Image\AbstractImageViewHelper;
13

14
/**
15
 * Renders an image tag for the given resource including all valid
16
 * HTML5 attributes. Derivates of the original image are rendered
17
 * if the provided (optional) dimensions differ.
18
 *
19
 * ## rendering responsive Images variants
20
 *
21
 * You can use the srcset argument to generate several differently sized
22
 * versions of this image that will be added as a srcset argument to the img tag.
23
 * enter a list of widths in the srcset to genereate copies of the same crop +
24
 * ratio but in the specified widths. Put the width at the start that you want
25
 * to use as a fallback to be shown when no srcset functionality is supported.
26
 *
27
 * ### Example
28
 *
29
 * ```
30
 * <v:media.image src="fileadmin/some-image.png" srcset="480,768,992,1200" />
31
 * ```
32
 *
33
 * ### Browser Support
34
 *
35
 * To have the widest Browser-Support you should consider using a polyfill like:
36
 * http://scottjehl.github.io/picturefill/
37
 */
38
class ImageViewHelper extends AbstractImageViewHelper
39
{
40
    use SourceSetViewHelperTrait;
41

42
    /**
43
     * name of the tag to be created by this view helper
44
     *
45
     * @var string
46
     * @api
47
     */
48
    protected $tagName = 'img';
49

50
    public function initializeArguments(): void
51
    {
52
        parent::initializeArguments();
6✔
53
        $this->registerUniversalTagAttributes();
6✔
54
        $this->registerTagAttribute(
6✔
55
            'usemap',
6✔
56
            'string',
6✔
57
            'A hash-name reference to a map element with which to associate the image.'
6✔
58
        );
6✔
59
        $this->registerTagAttribute(
6✔
60
            'ismap',
6✔
61
            'string',
6✔
62
            'Specifies that its img element provides access to a server-side image map.',
6✔
63
            false,
6✔
64
            ''
6✔
65
        );
6✔
66
        $this->registerTagAttribute(
6✔
67
            'alt',
6✔
68
            'string',
6✔
69
            'Equivalent content for those who cannot process images or who have image loading disabled.',
6✔
70
            true
6✔
71
        );
6✔
72
        $this->registerArgument(
6✔
73
            'srcset',
6✔
74
            'mixed',
6✔
75
            'List of width used for the srcset variants (either CSV, array or implementing Traversable)'
6✔
76
        );
6✔
77
        $this->registerArgument(
6✔
78
            'srcsetDefault',
6✔
79
            'integer',
6✔
80
            'Default width to use as a fallback for browsers that don\'t support srcset'
6✔
81
        );
6✔
82
    }
83

84
    public function render(): string
85
    {
86
        $this->preprocessImage();
×
87
        return $this->renderTag();
×
88
    }
89

90
    public function renderTag(): string
91
    {
92
        if (!empty($this->arguments['srcset'])) {
×
93
            $srcSetVariants = $this->addSourceSet($this->tag, $this->mediaSource);
×
94
        }
95

96
        if ($this->hasArgument('canvasWidth') || $this->hasArgument('canvasHeight')) {
×
97
            $width = $this->arguments['canvasWidth'];
×
98
            $height = $this->arguments['canvasHeight'];
×
99
            $src = $this->mediaSource;
×
100
        } elseif (!empty($srcSetVariants) && !empty($this->arguments['srcsetDefault'])) {
×
101
            $srcSetVariantDefault = $srcSetVariants[$this->arguments['srcsetDefault']];
×
102
            $src = $srcSetVariantDefault['src'];
×
103
            $width = $srcSetVariantDefault['width'];
×
104
            $height = $srcSetVariantDefault['height'];
×
105
        } else {
106
            $src = static::preprocessSourceUri($this->mediaSource, $this->arguments);
×
107
            $width = $this->imageInfo->getWidth();
×
108
            $height = $this->imageInfo->getHeight();
×
109
        }
110

111
        $this->tag->addAttribute('width', $width);
×
112
        $this->tag->addAttribute('height', $height);
×
113
        $this->tag->addAttribute('src', $src);
×
114

115
        /** @var string|null $alt */
116
        $alt = $this->arguments['alt'];
×
117
        // The alt-attribute is mandatory to have valid html-code, therefore add it even if it is empty
118
        $this->tag->addAttribute('alt', (string) $alt);
×
119

120
        if (empty($this->arguments['title'])) {
×
121
            $this->tag->addAttribute('title', $alt);
×
122
        }
123
        return $this->tag->render();
×
124
    }
125
}
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