kaiju_images.images module¶
- class ImageService[source]¶
Bases:
SQLService,AbstractRPCCompatibleThis service manages images including storage / conversion and galleries.
The concept is that you have an image file linked both to a file service and to an image service. Each image file may have different versions (sizes, colors etc.) derived from image converters. Such versions are interlinked using the original_id attribute present in each row (except original itself). Also there’s an option to create a “gallery” - an arbitrary user collection of images. It is managed by the correlation_id attribute.
{ "id": "", # image unique id "version", # version string (as in converters, for the original it's `None`) "correlation_id": "", # arbitrary correlation id to link different images in a gallery "original_id": "", # link to an original image id (for the original it's always `None`) "file_id": "", # link to a file object id in file service table "metadata": {} # additional metadata from converters / user / image service }
To create an image use a default SQLService.create method.
If you want to use a converter instead to create multiple version, you can use a provided method.
images = await image_service.convert_from_file( file_id=file_id, converter_id=converter_id, metadata={'test': True})
You can access galleries by correlation id using such method:
gallery = await image_service.get_gallery(correlation_id)
- service_name = 'images'¶
you may define a custom service name here
- converter_classes = ['ImageConverter']¶
- __init__(app, database_service, file_service=None, file_converter_service=None, permissions=None, logger=None)[source]¶
- Parameters:
app –
database_service (DatabaseService) –
file_service (FileService | None) –
file_converter_service (FileConverterService | None) –
logger –
- file_service¶
alias of
FileService
- async convert_image(id, converter_id, converter_settings=None, metadata=None, columns='*')[source]¶
Converts an image with a converter and saves all its versions. The image must be of original version.
- Parameters:
id (UUID) –
converter_id (UUID) –
converter_settings (dict | None) –
metadata (dict | None) –
columns (str | List[str] | None) –
- async convert_from_file(file_id, converter_id, converter_settings=None, metadata=None, correlation_id=None, columns='*')[source]¶
Converts file with a converter. This function will create an original version record as well.
- Parameters:
file_id (UUID) –
converter_id (UUID) –
converter_settings (dict | None) –
metadata (dict | None) –
correlation_id (UUID | None) –
columns (str | List[str] | None) –
- async get_gallery(id)[source]¶
Returns a gallery with all available most recent versions of images.
- Parameters:
id (UUID | List[UUID]) – list of correlation id