Handle image encoding properly