Don't let attachment image thumbnails overflow their containers.

Previously, image file attachments of certain dimensions would make
it possible for the thumbnail to overflow the thumbnail container,
which looked really ugly. We stop doing that now.

Reviewed at https://reviews.reviewboard.org/r/5444/.