The most important functions of this module are open and save_to_cache.
For the freedesktop specifications, it follows: http://jens.triq.net/thumbnail-spec/index.html
Convert the image in the file bytes of the image at a certain size. By consequence this byte data is different for the chosen format (JPEG, TIFF, ...).
Parameters: |
|
---|---|
Returns: | byte data of the thumbnail |
Get filename of freedekstop thumbnail.
Parameters: |
|
---|---|
Returns: | thumbnail filename |
Return type: | string |
Gets png metadata for the thumbnail.
Parameter: | filename (string) – image filename |
---|---|
Returns: | png info |
Return type: | PngImagePlugin.PngInfo |
Returns the freedesktop size label.
Parameter: | size (tuple of int) – requested size of the thumbnail |
---|---|
Returns: | size label |
Return type: | string |
>>> get_freedesktop_size_label((128, 128))
'normal'
>>> get_freedesktop_size_label((128, 129))
'large'
Get md5 hash of uri of filename.
Parameter: | filename (string) – filename |
---|---|
Returns: | hash |
Return type: | string |
>>> get_hash('file:///home/user/test.png')
'03223f4f10458a8b5d14327f3ae23136'
Get uri of filename.
Parameter: | filename (string) – filename |
---|---|
Returns: | uri |
Return type: | string |
>>> get_uri('/home/user/test.png')
'file:///home/user/test.png'
Small images don’t need thumbnails
Parameters: |
|
---|---|
Returns: | True if large enough, False otherwise |
Return type: | bool |
>>> im = Image.new('L', (128, 128))
>>> is_needed(im)
False
>>> im = Image.new('L', (1024, 1024))
>>> is_needed(im)
True
Retrieves a thumbnail from a file. It will only use the cache if size is smaller than the cache thumbnail sizes.
On Linux it will try to load it from the freedesktop thumbnail cache, which makes it much faster. Otherwise it will generate the thumbnail.
Parameters: |
|
---|---|
Returns: | thumbnail |
Return type: | pil.Image |
Save the thumb of image as a thumbnail for specified file.
This is called by the _open function, which requires that it returns the thumb.
Parameters: |
|
---|
Makes a not in place thumbnail
Parameters: |
|
---|---|
Returns: | thumbnail |
Return type: | Image |
>>> im = Image.new('L', (1024, 1024))
>>> thumbnail(im, (128, 128)).size
(128, 128)