Skip to content

Conversation

@stephankellermayr
Copy link
Contributor

Fixes #1500

Once again, a brilliant mathematician has pulled off a stroke of genius and caused the widths of the images not to be calculated correctly:

For example, the CSS states:
```css
.textmedia-item, .textpic-item {
	width: calc(50% -(40px / 2));
}
```

Which, for example, leads to an image size of 620px with a container width of 1280px. logical, because $1280 * 0.5 - 40 / 2 = 620$

PHP produces the same result in this case, as the gutters are removed first and then the multiplier is applied.
Mathematically a different way, but in this case the same result: $(1280 - 40) * 0.5 = 620$

However, if a different multiplier is used, such as 25% instead of 50%, the situation is unfortunately different.
CSS calculates: $1280 * 0.25 - 40 / 2 = 300$
And PHP calculates: $(1280 - 40) * 0.25 = 310$

**Ergo:**
If you want to reflect the calculation of image/text widths used in SCSS in PHP code, you would first have to apply the multiplier and then subtract half the gutter.
@stephankellermayr
Copy link
Contributor Author

Great, since the bugs are piling up here and I was careless, PR #1453 has also crept in here.

Anyway, probably nobody will take care of it in the foreseeable future anyway...

@stephankellermayr stephankellermayr changed the title Fix image width calculation in ImageVariantsUtility.php [BUGFIX] Fix image width calculation in ImageVariantsUtility.php Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong image width calculation in ImageVariantsUtility.php

2 participants