nexusLIMS.extractors.plugins.preview_generators.image_preview#
Image file preview generator.
Module Contents#
Classes#
Preview generator for standard image files. |
Functions#
Generate a preview thumbnail from a non-data image file. |
|
Load an image file from disk, down-sample it to the requested dpi, and save. |
API#
- nexusLIMS.extractors.plugins.preview_generators.image_preview.image_to_square_thumbnail(f: Path, out_path: Path, output_size: int) bool[source]#
Generate a preview thumbnail from a non-data image file.
Images of common filetypes will be transformed into 500 x 500 pixel images by first scaling the largest dimension to 500 pixels and then padding the resulting image to square.
- Parameters:
f – The string of the path of an image file for which a thumbnail should be generated.
out_path – A path to the desired thumbnail filename. All formats supported by
save()can be used.output_size – The desired resulting size of the thumbnail image.
- Returns:
Whether a preview was generated
- Return type:
- nexusLIMS.extractors.plugins.preview_generators.image_preview.down_sample_image(fname: Path, out_path: Path, output_size: Tuple[int, int] | None = None, factor: int | None = None)[source]#
Load an image file from disk, down-sample it to the requested dpi, and save.
Sometimes the data doesn’t need to be loaded as a HyperSpy signal, and it’s better just to down-sample existing image data (such as for .tif files created by the Quanta SEM).
- Parameters:
fname – The filepath that will be resized. All formats supported by
PIL.Image.open()can be usedout_path – A path to the desired thumbnail filename. All formats supported by
PIL.Image.Image.save()can be used.output_size – A tuple of ints specifying the width and height of the output image. Either this argument or
factorshould be provided (not both).factor – The multiple of the image size to reduce by (i.e. a value of 2 results in an image that is 50% of each original dimension). Either this argument or
output_sizeshould be provided (not both).
- class nexusLIMS.extractors.plugins.preview_generators.image_preview.ImagePreviewGenerator[source]#
Preview generator for standard image files.
This generator creates square thumbnail previews from image files (PNG, JPEG, TIFF, BMP, GIF) using PIL/Pillow.
- name#
‘image_preview’
- priority#
100
- supported_extensions#
Type: typing.ClassVar
- supports(context: ExtractionContext) bool[source]#
Check if this generator supports the given file.
- Parameters:
context – The extraction context containing file information
- Returns:
True if file extension is a supported image format
- Return type:
- generate(context: ExtractionContext, output_path: Path) bool[source]#
Generate a square thumbnail preview from an image file.
- Parameters:
context – The extraction context containing file information
output_path – Path where the preview image should be saved
- Returns:
True if preview was successfully generated, False otherwise
- Return type: