Previous topic

5.16. thumbnailers — Utilities to generate a thumbnail from a file

Next topic

5.16.2. thumbnailers.jfif — Thumbnailer for files containing a JPEG thumbnail

This Page

Languages

Previous versions

1.2
1.1

5.16.1. thumbnailers.base — Base classes for thumbnailers

class plmapp.thumbnailers.base.ThumbnailersManager[source]

Bases: object

The ThumbnailersManager has methods to register a thumbnailer with a type of file (an extension with the dot, like ".pdf") and to get a thumbnailer from a extension.

A thumbnailer is a function which takes 3 arguments:

  • input_path: path of the input file
  • original_filename: original filename, as uploaded by the user
  • output_path: path where the thumbnail should be saved.

It returns True if the generated thumbnail should be resized to THUMBNAIL_SIZE, False otherwise.

A thumbnailer must generate a png file. If it fails, it must raise an exception.

In all methods, extension should be in lowercase and starts with a dot.

THUMBNAIL_SIZE = (150, 150)

thumbnail size

classmethod register(extension, thumbnailer)[source]

Registers thumbnailer for extension.

classmethod get_best_thumbnailer(extension)[source]

Gets the best thumbnailer associated to extension. The best thumbnailer is the first registered thumbnailer for extension.

classmethod get_all_thumbnailers(extension)[source]

Returns a list of all thumbnailer associated to extension.

classmethod get_all_supported_types()[source]

Returns all supported types (a list of string).