-
-
Save ydrea/f8814b1ecdf6133b61f13f358eda5ea0 to your computer and use it in GitHub Desktop.
Arches Simple Thumbnailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import filetype | |
class SimpleThumbnailer(ThumbnailGenerator): | |
IMAGES = ( | |
'png', 'jpg', 'jpeg', 'jpe', 'gif', 'bmp', 'dib', 'dcx', | |
'eps', 'ps', 'im', 'pcd', 'pcx', 'pbm', 'pbm', 'ppm', | |
'psd', 'tif', 'tiff', 'xbm', 'xpm', | |
) | |
def make_thumbnail(self, inputfile_path, outputfile_path, **kwargs): | |
""" | |
Args: | |
inputfile_path: a path to a file on disk to create a thumbnail from | |
outputfile_path: a path to a file on disk where the thumbnail will be written to | |
Returns: | |
None | |
""" | |
file_type = filetype.guess(inputfile_path) | |
if file_type in IMAGES: | |
image = Image.open(inputfile_path) | |
image.thumbnail((300, 300)) | |
image.save(outputfile_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to use this with 'GENERATE_THUMBNAILS_ON_DEMAND = False', but it broke my gunicorn (took too much CPU time).
A first attempt of a fix is: