Cherry-picked commits to fix image scaling and thumbnailization