fix image conversion functions, add test