Fix broken image index calculation.