Skip to content

Thumbnailgenerator

flowtask.components.ThumbnailGenerator

ThumbnailGenerator

ThumbnailGenerator(loop=None, job=None, stat=None, **kwargs)

Bases: Boto3Client, FlowComponent

ThumbnailGenerator.

Overview
This component generates thumbnails for images stored in a DataFrame. It takes an image column, resizes the images
to a specified size, and saves them in a specified directory with a given filename format. The generated thumbnail
paths are added to a new column in the DataFrame.
.. table:: Properties
:widths: auto
+---------------------------+----------+-----------+---------------------------------------------------------------+
| Name                      | Required | Summary                                                                   |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| data_column               |   Yes    | The name of the column containing the image data.                         |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| thumbnail_column          |  Yes    | The name of the column to store the generated thumbnail paths.             |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| size                      |   Yes    | The size of the thumbnail. Can be a tuple (width, height) or a single     |
|                           |          | integer for a square thumbnail.                                           |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| format                    |   Yes    | The format of the thumbnail (e.g., 'JPEG', 'PNG').                        |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| directory                 |   No     | The directory where the thumbnails will be saved (default: ./thumbnails). |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| filename                  |   Yes    | The filename template for the thumbnails. It can include placeholders     |
|                           |          | for DataFrame columns (e.g., '{column_name}.jpg').                        |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| use_s3                    |   No     | Flag to save thumbnails in S3 instead of local disk.                      |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| s3_config                 |   No     | S3 configuration when use_s3 is True (default: default).                  |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| s3_prefix                 | Yes*     | S3 prefix/path for thumbnails (required when use_s3=True).                |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| url_thumbnail_column      |  No      | Column name to store the presigned URL of the thumbnail                   |
|                           |          | (default: url_thumbnail).                                                 |
+---------------------------+----------+-----------+---------------------------------------------------------------+
| thumbnail_directory_column|  No      | Column name to store the base directory/URL for thumbnails                |
|                           |          | (default: thumbnail_directory).                                           |
+---------------------------+----------+-----------+---------------------------------------------------------------+
Returns
This component returns a DataFrame with new columns containing the paths and URLs of the generated thumbnails.
Example:
```
- ThumbnailGenerator:
    data_column: image
    thumbnail_column: thumbnail_photo
    size: (128, 128)
    format: JPEG
    filename: {photo_id}.jpg
    use_s3: true
    s3_prefix: /thumbnails/epson
```

open async

open(**kwargs)

Override open method to only process S3 when needed