encode image data only if image is not encoded yet