When adding attributes to the image (via say a preprocess function) these attributes are ignored.

The patch bellow solves the problem by including the attributes. It is basically a copy of theme_image_formatter.