Image converter code (without test cases)