File::adjustThumbWidthForSteps manipulates thumbnail widths to fit the ThumbnailSteps config var when generating thumbnails and thumbnail links from PHP, and I've recently added a JS implementation that's meant to give the same results in mw.util.adjustThumbWidthForSteps for extensions such as Popups to use (T411013).
There's some question about the details of the logic though, which we should decide on and fix on both ends for all core & extensions code to use consistently. :)
Current logic:
- for each step:
- if the step is larger than the original size, return the requested size
- if the step is exactly the requested size, return the requested size
- if the step is larger than the requested size, return the step size
- if the requested thumb is larger than the step, but smaller than the original, return the requested size
I think the main open question is whether to change case 1) to return the original file instead of generating the requested thumbnail size -- in the case of Pops for instance we might have it ask for a 640px thumbnail of a 900px image: it's past the 500px step but before the 960px step and ends up returning a 640px thumbnail instead of rounding up to the full-size image.
(Note JS callers such as Popups will need to be able to distinguish between original-size and thumbnails when generating URLs, to avoid generating calls to exact-size thumbnails. This logic, also should be encapsulated some time.)
CC'ing @Ladsgroup as this is relevant to ongoing work with thumbnail size normalization.