Function to resize and convert images.