/symfony-ux-skills:ux-imagefrom symfony-ux-skills
Renders responsive img and picture tags with srcset, sizes, and layout styles via URL-based providers (Cloudflare, Cloudinary, imgix, Imagor, IPX, KeyCDN). Use for Twig components and PHP image URL generation.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Render responsive images: srcset, sizes, loading, dimensions and a layout style, with every transformation delegated to a URL-based image provider. Without decoding or resizing anything itself, the package lets you switch providers and keep your templates.
Since Symfony UX 3.6+. The package is experimental: its API may still change.
composer require symfony/ux-image
composer require symfony/ux-twig-component # for the Twig functions and components
composer require symfony/ux-cloudflare-image # one provider bridge
Without TwigComponent, only the ImageUrlGenerator service is available (enough for an API or a worker).
# .env
UX_IMAGE_DSN=null://null # default: original URL, no srcset, keeps dimensions and style
# .env.prod
UX_IMAGE_DSN=cloudflare://cdn.example.com
| Scheme | Package | DSN example |
|---|---|---|
cloudflare | symfony/ux-cloudflare-image | cloudflare://cdn.example.com |
cloudinary | symfony/ux-cloudinary-image | cloudinary://my-cloud?origin=https://example.com |
imagor | symfony/ux-imagor-image | imagor://images.example.com?origin=https%3A%2F%2Fexample.com&sign_key=... |
imgix | symfony/ux-imgix-image | imgix://my-source.imgix.net |
ipx | symfony/ux-ipx-image | ipx://images.example.com |
keycdn | symfony/ux-keycdn-image | keycdn://myzone.kxcdn.com |
<twig:ux:image src="/uploads/hero.jpg" alt="Hero" width="800" height="450" />
{# Above the fold / likely LCP: eager and high priority #}
<twig:ux:image src="/uploads/hero.jpg" alt="Hero" width="1200" height="600" priority />
{# One <source> per format, then the <img> fallback #}
<twig:ux:picture src="/uploads/hero.jpg" alt="Hero" width="800" height="450" />
src is the public path of the original, as your application serves it. Functions take the same options as a third argument (camelCase keys) and HTML attributes as a fourth:
{{ ux_image('/uploads/hero.jpg', 'Hero', {width: 800}, {class: 'rounded'}) }}
{{ ux_picture('/uploads/hero.jpg', 'Hero', {width: 800, height: 450}) }}
Single URL (Open Graph, email, CSS background, API):
<meta property="og:image" content="{{ absolute_url(ux_image_url('/uploads/hero.jpg', {width: 1200, height: 630})) }}">
use Symfony\UX\Image\ImageUrlGenerator;
$url = $this->imageUrlGenerator->generate('/uploads/hero.jpg', width: 1200, height: 630);
| Prop | Default | Notes |
|---|---|---|
src, alt | required | |
layout | constrained | fixed, constrained or full-width |
width, height | null | fixed/constrained require width; full-width requires height |
fit | cover when both dimensions are set | cover crops, contain letterboxes |
format | null | Pins one format: no negotiation, no <source> |
quality | null | 1 to 100 |
priority | false | loading="eager" fetchpriority="high" instead of loading="lazy" |
object-fit (objectFit in functions) | the fit value | |
breakpoints | resolutions option | srcset widths for this image |
operations | {} | Provider-specific, keyed by provider name |
preset | null | Named transformation set |
Other attributes pass through to <img> and win over generated ones. A caller style merges with the layout style; a caller sizes replaces the generated one.
| Layout | srcset widths | sizes | Style |
|---|---|---|---|
fixed | width, 2 x width | {width}px | fixed width and height |
constrained | width, 2 x width, ladder entries below 2 x width | (min-width: {width}px) {width}px, 100vw | max-width, aspect-ratio, width: 100% |
full-width | whole ladder | 100vw | width: 100%, aspect-ratio |
The generated sizes assumes the image spans the viewport below its width. In grids and sidebars, pass your own:
<twig:ux:image src="/uploads/card.jpg" alt="Card" width="400" height="300"
sizes="(min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw" />
# config/packages/ux_image.yaml
ux_image:
provider: '%env(resolve:UX_IMAGE_DSN)%' # resolve: is required
formats: ['avif', 'webp', 'jpeg'] # preference order, intersected with the provider's
resolutions: [6016, 5120, 4480, 3840, 3200, 2560, 2048, 1920, 1668, 1280, 1080, 960, 828, 750, 640]
quality: null # null leaves it to the provider
presets:
thumbnail: { width: 200, height: 200, quality: 70 }
og: { width: 1200, height: 630, format: jpeg }
vintage:
operations:
cloudflare: { saturation: 0.3, contrast: 1.2 }
<twig:ux:image src="/uploads/hero.jpg" alt="Hero" preset="thumbnail" />
{{ ux_image_url('/uploads/hero.jpg', {preset: 'og'}) }}
Presets hold only width, height, fit, format, quality and operations. Template values win per key; operations merge per provider and per operation.
<img> or <picture>The provider never picks the element: the caller does. ux_image() always renders one <img>: providers that negotiate (Cloudflare, Cloudinary, imgix, IPX) still serve a modern format; otherwise the last surviving entry of formats is used. ux_picture() renders one <source> per format, which suits providers without negotiation (Imagor, KeyCDN) and caches that ignore Vary: Accept. Art direction (different crops per media query) is out of scope.
<twig:ux:image src="/uploads/hero.jpg" alt="Hero" width="800"
:operations="{cloudflare: {sharpen: 1}, keycdn: {sharpen: 10}}" />
Only the active provider's entry is read. An unsupported operation, or a key naming a provider that is not installed, throws an exception. See references/providers.md for the operations, DSN options and signing of each provider.
Set priority on the LCP image. Everything is lazy by default; a lazy hero delays Largest Contentful Paint.
Version the path when replacing an original. Variants are cached by path and parameters: rather than reusing the name, use /uploads/hero.3f2a1c.jpg.
Develop with null://null. Templates, dimensions and layout styles are identical; only transformations are skipped.
Protect transformations in production. Each distinct URL is a new variant to generate and cache: enable URL signing where the provider supports it.
Keep formats and resolutions short. Every candidate is one more variant on the CDN.
InvalidArgumentException: missing width for fixed/constrained (or height for full-width), unknown option or preset, a format or operation the provider does not support, a DSN option it does not accept, or an empty formats intersection.%kernel.project_dir% in the DSN not resolved: use %env(resolve:UX_IMAGE_DSN)%.api_secret.symfony/ux-image on Packagist.<twig:ux:image> in your own card or media components.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package./turboSymfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast]./twig-componentSymfony UX TwigComponent: reusable Twig buttons, cards, alerts and design system components. Use for twig: tags, #[AsTwigComponent], props, blocks, attributes.defaults(), anonymous components, computed properties, provide()/inject() and html_cva./ux-autocompleteSymfony UX Autocomplete: searchable selects and Ajax suggestions for large Symfony form lists. Use for EntityType, ChoiceType, Tom Select, the autocomplete option, #[AsEntityAutocompleteField], #[AsAutocompleteField], AutocompleterInterface, extra_options and tom_select_options.Other plugins' skills for the same job