Add `fallback` image style

Created on 19 June 2025, 23 days ago

Problem/Motivation

We need a default fallback image style to protect a website from users uploading large image files and having those files rendered to the end-users.

Steps to reproduce

1. Create a `Page` content and upload a 50 MB image to all image fields.
2. Save the page and observe that Banner image (and other images) are shown using their original file (and size).

Proposed resolution

Add a default `fallback` image style that will be applied to all images that do not specify a custom image style explicitly.

The pre-processing for images currently takes place within `civictheme_media_image_get_variables()` function. This function accepts an `$image_style` parameter which is currently set to `NULL`. The proposal is to create a `civictheme_fallback` image style with some sensible defaults (downscale to 1500x1500, preserving ratio) and set this as a default value for the `$image_style` parameter. This will ensure that all images pre-processed via CivicTheme's functions will be downsized.

Note that consumer sites can always update the proposed default values of the `fallback` image style as they see fit.

Remaining tasks

1. Decide on the image style name. Proposal `civictheme_fallback`.
2. Decide on the default values. Proposal is `1500x1500`
3. Add image style
4. Add image style name to the `civictheme_media_image_get_variables()` function as a default value for the second argument.
5. Add tests that assert the present of the `styles` substring in the rendered output of, say, Banner featured image source URL.

User interface changes

None

API changes

None

Data model changes

None

Feature request
Status

Active

Version

1.11

Component

Code

Created by

🇦🇺Australia alex.skrypnyk Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024