For twitter/og cards, resize and pad portrait images

Hi there,
When showing twitter/og cards, sometimes my post has a portrait image. Does anyone know of any way to use the image processing functions to resize to a fixed size, retain the aspect ratio AND pad the image if required?

For example, ($resource.Fit "2048x1024" ) maintains the aspect ratio, but does not pad the image. If you have a portrait image, then the final image size might be 512x1024.

I would like an image that is 2048x1024, with white padding either side of the 512 “real” pixels.