fixed img to binary function