Fix invalid HTML when serializing images