You might want to try the very new and simple CSS3 feature:
img {
object-fit: contain;
}
It preserves the picture ratio (as when you use the background-picture trick), and in my case worked nicely for the same issue.
Be careful though, it is not supported by IE (see support details here).