algoo / preview-generator

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

get_jpeg_preview creates pdf of tlf with white border #99

Closed stm-clemens closed 5 years ago

stm-clemens commented 5 years ago

Hey,

i want to generate thumbnails for my entire image library. os.walk gives me a list with every image file. everything works fine with jpeg. But as soon as I want to generate thumbnails for my tifs it creates pdf's with white border und gives me a jpeg of that pdf with the same white border.

Is there a way to create tif thumbnails without the white border?

thats how I start the process:

for folders_ in settings.FILE_DIR:
    files_found = getFiles(os.path.join(os.getcwd(), folders_))
    manager = PreviewManager(settings.THUMB_DIR, create_folder= True)
    for image_ in files_found:
        preview_ = manager.get_jpeg_preview(image_, width=1024, height=1024,  file_ext=os.path.splitext(image_)[1])

and thats the output: adf122979d73f41bdf6e69b51696a1ec-1024x1024 c0c4ec7556ce7613624a7eafc5d8597a.pdf

inkhey commented 5 years ago

Hello @stm-clemens and thank for this feedback.

That's a bug. Preview_generator rely on many "builders" which use each differents softwares to create image. I think, the issue is probably related to using an incorrect builder like libreoffice builder.

if you want to try a fix, updating LO_MIMETYPES of office__libreoffice.py may probably solve the issue.

stm-clemens commented 5 years ago

Hey thanks for your reply.

That works. Nice :) But now I get the following error: ValueError: Decompressed Data Too Large

My tif file is 238,9MB.

inkhey commented 5 years ago

Hey thanks for your reply.

That works. Nice :)

Nice, we are currently not sure about how we should patch this for future release as tiff does support some weird case like multipages files.

But now I get the following error: ValueError: Decompressed Data Too Large

My tif file is 238,9MB.

Currently preview_generator isn't ready to deal with big file as softwares it used under the hood have some kind of restriction by default for security purpose. We already see this for imagemagick-based generated which doesn't allow too big file by default.

For your issue, with rapid research, it's seems to be a limitation of pillow : https://stackoverflow.com/questions/42671252/python-pillow-valueerror-decompressed-data-too-large .

stm-clemens commented 5 years ago

Thanks :)

I set the LOAD_TRUNCATED_IMAGES to true and it works :)

It takes its time but it works :)

lebouquetin commented 5 years ago

@stm-clemens thanks for your investigation. @inkhey I suggest we add an option for allowing large files... what do you think?

inkhey commented 5 years ago

@lebouquetin Having such option should be nice but all those limitation simply cannot be removed by command line:

ImageMagick for example has strict size limitation for security purpose that cannot be change without modifying confg file, see https://www.imagemagick.org/discourse-server/viewtopic.php?t=31438.

The other problem is that limitation can come from different parameters depending on the builders, for exemple, imagemagick has a width and height limitation, but we can have also an size limitation and some other more weird case like in this problem for pillow which have a limitation on metadata size. Not sure that's easy to rationalize.

So, i think, we should first documentate how to override thoses limitations. As far i know there is no need to change preview_generator code for this if we set value in code using preview_generator or set conf file.

Then as far as we understood this, we may think about having option to have support for size limit and height/width limit which will set in preview_generator code itself most of the needed thing to make it work (but not config file of course).