Generalizing pterk's ZeroDivisionError fix for 1px images