[Answer]-Django ImageFile _get_image_dimensions() returns None

1👍

If you read the code. You’ll see that get_image_dimensions reads a chunk from the file and tries to parse it into an image with PIL. If it fails, it increases the chunksize and repeats. (Increasing the chunksize is to read the whole file in less reads than (filesize/initial chunksize) times. Fileformats like TIFF need to read the while file.)

Returning None may happen in 3 cases.

  1. An empty file. And the first chunk read is empty.
  2. After reading the whole file, PIL can still not parse it into a file. Is your file complete? Is it an image?
  3. If Pillow sets the size to None. Try using PIL directly on you machine and see it can parse your file.

Leave a comment