0

I have a app to generate thumbnail for images using preview-generator, before processing the image I want to check the image prosperities such as size,dimensions, ppi etc.

But when I open image using Pillow to read image resolution the preview-generator method get_jpeg_preview raise exception error.

zero-length blob not permitted `' @ error/blob.c/BlobToImage/351

from PIL import Image
from preview_generator.manager import PreviewManager

manager = PreviewManager(CACHE_PATH, create_folder=True)

file_object = request.files['file']
size = file_object.content_length
img = Image.open(file_object)
dimensions = img.size
if validate(size, dimension):
    manager.get_jpeg_preview(filepath, height=512)

If I close the Pillow open file by img.close() I get below error.

ValueError: read of closed file

If I remove Pillow code to get dimension it works fine.

from PIL import Image
from preview_generator.manager import PreviewManager

manager = PreviewManager(CACHE_PATH, create_folder=True)

file_object = request.files['file']
size = file_object.content_length
#img = Image.open(file_object)
#dimensions = img.size
if validate(size, None):
    manager.get_jpeg_preview(filepath, height=512)

Note: preview-generator uses multiple lib including Pillow and Wand. Also is there any other way to get image resolution?

Avanish
  • 1
  • 1
  • Welcome to StackOverflow! Please check the [how to ask](https://stackoverflow.com/help/how-to-ask) help section, and what a [mre] is. Kindly [edit](https://stackoverflow.com/posts/67520899/edit) your question then to provide such, since your code as-is misses a lot of dependencies, and thus is not runnable. – HansHirse May 14 '21 at 06:45
  • You can read a "file" from request.files only once. It is a stream, so when you read it, you will empty it. see here https://stackoverflow.com/questions/17733133/loading-image-from-flasks-request-files-attribute-into-pil-image – pippo1980 May 14 '21 at 10:51

0 Answers0