---
title: "Responsive Images"
manual: "CKEditor Image Support"
version: "13.11"
permalink: "https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:examples-responsive-images@13.11"
source: "Examples/Responsive-Images.rst"
rendered: "2026-11-23T12:52:55+00:00"
---

# Responsive Images {#examples-responsive-images}

Examples for implementing responsive images with srcset and automatic generation.

**Table of Contents**

-   [Automatic srcset Generation](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:automatic-srcset-generation@13.11)
-   [Related Documentation](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:related-documentation@13.11)

## Automatic srcset Generation {#automatic-srcset-generation}

**Objective**: Generate responsive images with srcset

### TypoScript Setup {#typoscript-setup}

**EXT:my_site/Configuration/TypoScript/setup.typoscript**

```typoscript
lib.parseFunc_RTE {
    tags.img = TEXT
    tags.img {
        current = 1
        preUserFunc = MyVendor\MySite\UserFunc\ResponsiveImageRenderer->render
    }
}
```

### PHP Implementation {#php-implementation}

**EXT:my_site/Classes/UserFunc/ResponsiveImageRenderer.php**

```php
namespace MyVendor\MySite\UserFunc;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class ResponsiveImageRenderer
{
    private ?ContentObjectRenderer $cObj = null;

    // Called by TYPO3 before render()
    public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
    {
        $this->cObj = $cObj;
    }

    // TYPO3 v14 calls only methods marked with #[AsAllowedCallable]
    #[AsAllowedCallable]
    public function render(
        ?string $content,
        array $conf,
        ServerRequestInterface $request
    ): string {
        // <img> is an empty tag: parseFunc passes no content to tags.img,
        // but puts the tag's attributes into the content object's parameters.
        $attributes = $this->cObj?->parameters ?? [];
        $originalTag = '<img ' . trim((string)($attributes['allParams'] ?? '')) . '>';

        $fileUid = (int)($attributes['data-htmlarea-file-uid'] ?? 0);
        if ($fileUid <= 0) {
            return $originalTag;
        }

        try {
            $file = GeneralUtility::makeInstance(ResourceFactory::class)
                ->getFileObject($fileUid);
        } catch (\Exception) {
            return $originalTag;
        }

        // Never expose a file from a non-public storage
        if (!$file->getStorage()->isPublic()) {
            return '';
        }

        // Generate responsive variants
        $breakpoints = [480, 768, 992, 1200, 1920];

        $srcsetParts = [];
        foreach ($breakpoints as $width) {
            $processedFile = $file->process(
                ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
                ['width' => $width]
            );
            $srcsetParts[] = $processedFile->getPublicUrl() . ' ' . $width . 'w';
        }

        $srcset = implode(', ', $srcsetParts);
        $sizes = '(max-width: 768px) 100vw, (max-width: 992px) 50vw, 33vw';

        return '<img srcset="' . htmlspecialchars($srcset) . '"'
            . ' sizes="' . $sizes . '" '
            . trim((string)($attributes['allParams'] ?? '')) . '>';
    }
}
```

> [!NOTE]
> This renderer replaces the extension's `renderImageAttributes()` for
> `tags.img`, so quality scaling and the other processing of the extension
> no longer run for these images; the example repeats only the non-public
> storage check. Captioned images are rendered by `renderFigure()` through
> `externalBlocks.figure` and never reach this renderer.

### Result HTML {#result-html}

```html
<img
    src="/fileadmin/image.jpg"
    srcset="/fileadmin/_processed_/image_480.jpg 480w,
            /fileadmin/_processed_/image_768.jpg 768w,
            /fileadmin/_processed_/image_992.jpg 992w,
            /fileadmin/_processed_/image_1200.jpg 1200w,
            /fileadmin/_processed_/image_1920.jpg 1920w"
    sizes="(max-width: 768px) 100vw, (max-width: 992px) 50vw, 33vw"
    alt="Image description"
/>
```

**Result**: Automatic responsive images ✅

## Related Documentation {#related-documentation}

-   [Advanced Features](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:examples-advanced-features@13.11) \- Lightbox and lazy loading
-   [Integration & Configuration](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:integration@13.11) \- Configuration guide
-   [Controllers API](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:api-controllers@13.11) \- Controller APIs
