File thumbnailer is "saner" file thumbnailer with as little weird depedencies as possible
Supported file formats are all images supported by Pillow OOTB and all files supported by PyMuPDF (if installed)
$ pip install file-thumbnailer
$ pip install file-thumbnailer[pdf] # for PyMuPDF support
You can also use these repositories maintained by me
Add repository by running these commands
$ wget -O- https://repository.salamek.cz/deb/salamek.gpg | sudo tee /usr/share/keyrings/salamek-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/salamek-archive-keyring.gpg] https://repository.salamek.cz/deb/pub all main" | sudo tee /etc/apt/sources.list.d/salamek.cz.list
And then you can install a package python3-file-thumbnailer
$ apt update && apt install python3-file-thumbnailer
from file_thumbnailer.ConverterManager import ConverterManager
from file_thumbnailer.models.Dimensions import Dimensions
converter_manager = ConverterManager()
with open('my_file.pdf', 'rb') as read_file:
converter = converter_manager.from_data(read_file
thumbnail = converter.to_image_bytes(Dimensions())
with open('my_file_thumbnail.jpg', 'wb') as thumbnail_file:
thumbnail_file.write(thumbnail)