Aspect ratio configuration only supports integer numerator/denominator

Created on 3 December 2024, about 2 months ago

Problem/Motivation

On using decimal numbers when specifying aspect ratios, I noticed that the numerator and denominator are rounded down to be integers (most likely through the application of intval). For example, an aspect ratio value "2.6x1" seems to be treated as "2x1".

Steps to reproduce

Configure a view mode for at least one media size using the property aspect-ratios: '2.613430127x1'.

Observe that the field formatter will produce an image with an aspect ratio of 2:1 as opposed to 2.613430127:1.

Workaround: Convert the aspect ratios to use only integer numerators and denominator (e.g. aspect-ratios: '1440x551').

Proposed resolution

Support decimal numbers in aspect ratio configurations. This can be done by either converting the input ad-hoc into integer form or by using decimal values directly (which should be perfectly fine and lead to more accurate results when doing math like determining the desired height of an image with the formula $width / ($aspect_ratio_numerator / $aspect_ratio_denominator))

Remaining tasks

I don't know.

User interface changes

None (apart from formally supporting a wider range of input values).

API changes

None, I think.

Data model changes

Yes, I think. The code seems to make use of the global function intval in several places either for the purpose of parsing the aspect ratio configuration or setting width and/or height values. These would need adjustment.

Integer values for widths and heights are required to be used when setting the width and height HTML content attributes (which are integer values without a unit), but for setting, for example, widths and heights via CSS and the HTML content attribute style (e.g. style="width: 123.45px;"), decimal values are perfectly fine.

🐛 Bug report
Status

Active

Version

1.3

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024