Don't iterate when there aren't image sizes

Fixes #1459