ORM utilities
Thumbnail management
The ORM uses the ThumbnailPath column of ImageInstance to store thumbnail path and state:
- NULL means that the image contains no thumbnail and the thumbnail generation code must be ran on this image.
- An empty string indicates that the thumbnail generator ran and failed for this image.
- Any other value will be interpreted as a relative path to the image thumbnail within the
THUMBNAILS_PATHdirectory. In practice, the thumbnail generator will generate multiple thumbnail sizes and a suffix must be appended to correctly locate a thumbnail file. For example, the thumbnail of 144px (side) will be stored at<THUMBNAILS_PATH>/<image.ThumbnailPath>_144.jpg.
This section explains how to update thumbnails in the database, potentially after the thumbnail generation code has been updated.
Generating thumbnails
The ORM contains a simple update_thumbnails script that will update thumbnails in the database:
eorm update-thumbnails --env prodThis example uses an environment called prod to determine what database to connect to and where to write thumbnails. This environment must be provided in a .env file as explained in ORM Configuration.
By default, eorm update-thumbnails will run for images with ThumbnailPath == NULL. To run also on images with failed thumbnails (useful after the thumbnail generation code has been updated) use:
eorm update-thumbnails --failed --env prodUpdating thumbnail generation code
To updated the thumbnail generation code to support new image types or generally change the way thumbnails are generated:
-
Update the thumbnail generation code. The ORM includes a notebook to easily visualize the output of these methods on a sample images from the database.
-
For any images that need to be updated in the database, set
ThumbnailPathto NULL. -
Run the thumbnail update script:
eorm update-thumbnails --failed --env prod