(Spun out of T188636)
Our thumbnail handling in Page previews is quite complex:
https://github.com/wikimedia/mediawiki-extensions-Popups/blob/master/src/ui/thumbnail.js
Ideally the page previews client would not need to do any of this and the thumbnail served by the page summary endpoint would have information about whether an image was portrait/landscape