algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
235 stars 51 forks source link

Cannot generate preview from .ai file #215

Closed forfin closed 3 years ago

forfin commented 3 years ago

Version: 0.15.4

I got this error when trying to generate preview from the .ai file.

Traceback (most recent call last):
--
File "/home/app/app.py", line 33, in handler
force=True,
File "/usr/local/lib/python3.7/site-packages/preview_generator/manager.py", line 186, in get_jpeg_preview
mimetype=preview_context.mimetype,
File "/usr/local/lib/python3.7/site-packages/preview_generator/preview/builder/image__pillow.py", line 255, in build_jpeg_preview
result = self.image_to_jpeg_pillow(img, size)
File "/usr/local/lib/python3.7/site-packages/preview_generator/preview/builder/image__pillow.py", line 270, in image_to_jpeg_pillow
with Image.open(png) as image:
File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2959, in open
"cannot identify image file %r" % (filename if filename else fp)
PIL.UnidentifiedImageError: cannot identify image file <_io.BufferedReader name='/mnt/tmp/32b480e1-228b-4c30-aeaa-885be0fa3b9buploadsggp-m2.testckmelkxz700123u5y90ubl4qpTANGKA11.ai'>
forfin commented 3 years ago

I have create repository to reproduce this issue https://github.com/forfin/issue-preview-generator-215

inkhey commented 3 years ago

Hello, We currently do not really support illustator file, we only support .eps for now, but the supported list is misleading for this. It's look to be an issue in python mimetype guesser, which make wrong guess because .ia was previously .eps, they are now .pdf. I created a bug in python upstream about this weird situation:https://bugs.python.org/issue43544.

I suggest you, to try either tweaking the mimetype base or forcing a pdf mimetype for this file during the conversion, if you have the dependency required for the pdf builder, it should work.

I don't know if there are big differences between a pdf generated from a .ai and an .ai loaded with a true vector software. It may be useful or not to use inkscape builder to generate those if the generated previous is more correct that just loading it as pdf.

I hope this will help you :smiley:

forfin commented 3 years ago

Thank you, I override mimetype by add file_ext='.pdf' when calling get_jpeg_preview and it can generate the preview. I guess I will use this as workaround.