Only consider unique image attributes when determining best match.

This fixes cases where `tag attr1 attr2` and `tag attr2 attr2` are given equal precedence and thus cause an ambiguity error.