algoo / preview-generator

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

Bug:failed generate png picture thumbnail but some others succeed #268

Open hatcherfang opened 2 years ago

hatcherfang commented 2 years ago

Description and expectations

I generate some png files' thumbnail failed, but some others succeed when I use the manager.get_jpeg_preview.

How to reproduce

from preview_generator.manager import PreviewManager

path = '/tmp/IMG20200422_094758.png'                                                  
cache_path = "/tmp/cache/"                                                            
manager = PreviewManager(cache_path, create_folder=True)                              
path_to_preview_image = manager.get_jpeg_preview(path, force=True)

the image as below: IMG20200422_094758

but the other image is ok as below: huizhang

Version information

raphj commented 2 years ago

Is there an error message?

hatcherfang commented 2 years ago

Is there an error message? Yes, the error message is as below:

File "test3.py", line 7, in <module>
path_to_preview_image = manager.get_jpeg_preview(path, force=True)
File "/usr/local/lib/python3.6/site-packages/preview_generator/manager.py", line 203, in get_jpeg_preview
mimetype=preview_context.mimetype,
File "/usr/local/lib/python3.6/site-packages/preview_generator/preview/builder/image__imconvert.py", line 131, in build_jpeg_preview
source_path=file_path, dest_path=tmp_png.name, mimetype=mimetype
File "/usr/local/lib/python3.6/site-packages/preview_generator/preview/builder/image__imconvert.py", line 164, in _imagemagick_convert
stderr=STDOUT,
File "/usr/local/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['convert', 'png:/tmp/IMG20200422_094758.png', '-layers', 'merge', '/tmp/preview-generator-y7qu4wdy.png']' returned non-zero exit status 1.
Felti commented 2 years ago

i got the same error for PNG some get converted and some not

raphj commented 2 years ago

What happens if you run the given convert command manually? Is there a meaningful error?

convert png:/tmp/IMG20200422_094758.png -layers merge /tmp/preview-generator-y7qu4wdy.png
Felti commented 2 years ago

i did some tests, it appear that when the image have been converted to something other than it's original extension, it triggers the errors, must be something related to the mimeType check (ex : .png , image/jpg), otherwise when the file/img extension is the same as the mimeType (ex : .png , image/png) it doesn't

raphj commented 2 years ago

So you run into errors when attempting to preview a .png file which is actually a JPEG image, is that it? Do I understand correctly?

@hatcherfang is /tmp/IMG20200422_094758.png indeed a PNG image or is it actually a JPG image? GitHub actually did a jpeg preview for your image.

Felti commented 2 years ago

So you run into errors when attempting to preview a .png file which is actually a JPEG image, is that it? Do I understand correctly?

yes indeed

raphj commented 2 years ago

Is it acceptable for you to use the extension that matches the right mime type, or perhaps no extension at all if difficult? Indeed the wrong extension will confuse the various tools we use to detect types.

@inkhey we have an error when attempting to convert a file that does not have the correct extension.

Le 06/09/2021 à 16:20, Mad Tofu a écrit :

So you run into errors when attempting to preview a .png file
which is actually a JPEG image, is that it? Do I understand correctly?

yes indeed

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/algoo/preview-generator/issues/268#issuecomment-913686718, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5D7FPKQTBT2DARQLFNNSDUATE3FANCNFSM5C5AHEBA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.