Adding letterboxing & pillarboxing when aspect ratios of original and final image are different

Adding letterboxing and pillarboxing accordingly to the image when the expected final image aspect ratio is not same as the original image aspect ratio