modosaic.services.image¶
modosaic.services.image ¶
ImageService ¶
Image conversion helpers shared by generators and validators.
bytes_to_pil
staticmethod
¶
bytes_to_pil(image_bytes)
Decode encoded image bytes into an RGB PIL image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_bytes
|
bytes
|
Encoded image bytes. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
RGB PIL image. |
Source code in modosaic/services/image.py
13 14 15 16 17 18 19 20 21 22 23 | |
save_bytes_to_tmp_file
staticmethod
¶
save_bytes_to_tmp_file(image_bytes, suffix='.jpg')
Save encoded image bytes to a temporary image file.
Callers own cleanup for the returned path. Prefer
temporary_image_file when the file is only needed within one scoped
operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_bytes
|
bytes
|
Encoded image bytes. |
required |
suffix
|
str
|
Filename suffix for the temporary file. |
'.jpg'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created temporary file. |
Source code in modosaic/services/image.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
temporary_image_file
staticmethod
¶
temporary_image_file(image_bytes, suffix='.jpg')
Yield a temporary image file path and remove it when the scope exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_bytes
|
bytes
|
Encoded image bytes. |
required |
suffix
|
str
|
Filename suffix for the temporary file. |
'.jpg'
|
Yields:
| Type | Description |
|---|---|
Path
|
Path to the temporary image file. |
Source code in modosaic/services/image.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |