Skip to content

Loading corrupted or partially downloaded image files

Adam Geitgey edited this page Apr 2, 2018 · 1 revision

If you try to load an image file that is corrupt (half downloaded, for example):

import face_recognition
img = face_recognition.load_image_file("bad_file.jpg)

You'll get an error saying the file must be uint8 or a PIL image.

If you REALLY want to force Python / PIL to load a corrupted or partial image, you can do this:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

import face_recognition
img = face_recognition.load_image_file("bad_file.jpg)

In some cases, that might allow you to work around a corrupted image file as best as possible.