Aspect ratio configuration only supports integer numerator/denominator

Created on 3 December 2024, 19 days 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

  • Issue created by @philipprudloff
  • 🇩🇪Germany D34dMan Hamburg

    Updated Workaround proposed in issue summary to continue with the aspect ratio that was used earlier.

  • 🇩🇪Germany D34dMan Hamburg

    @philipprudloff,

    The intval check and requirement is coming from a dependency of this module which requires integer value for Defining Crop.
    Until that module ( Crop ) supports float value for crop, we can't.

    .

    How about we add a field validation while configuring Aspect ratio, so that an error message is shown to the end user?

    • d34dman committed 642a3243 on 1.x
      Issue #3491278 by d34dman, philipprudloff: Aspect ratio configuration...
Production build 0.71.5 2024