VID-1810 Redo the janky image handling that existed before

Lines 1342-1358 were moved to method `fitWithin` below with the `$imagesDimensions` variable shortened to `$dim`