pixano.features.schemas.views.image
Image(created_at=None, updated_at=None, **data)
Bases: View
Image view.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
The image URL. Can be relative or absolute or a data URL. |
width |
int
|
The image width. |
height |
int
|
The image height. |
format |
str
|
The image format. |
Source code in pixano/features/schemas/base_schema.py
open(media_dir=None, output_type='base64')
Open the image.
Note
If the output type is "base64", the image is returned as a base64 string formatted as "data:image/{image_format};base64,{base64}".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
media_dir
|
Path | None
|
Path to the media directory. If the URL is relative, it is relative to this directory. |
None
|
output_type
|
Literal['base64', 'image']
|
The output type. Can be "base64" or "image" (PIL.Image). |
'base64'
|
Returns:
Type | Description |
---|---|
str | Image
|
opened image. |
Source code in pixano/features/schemas/views/image.py
open_url(url, media_dir=None, output_type='base64')
staticmethod
Open an image from a URL.
Note
If the output type is "base64", the image is returned as a base64 string formatted as "data:image/{image_format};base64,{base64}".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
image url relative to media_dir or absolute. |
required |
media_dir
|
Path | None
|
path to the media directory if the URL is relative. |
None
|
output_type
|
Literal['base64', 'image']
|
output type. Can be "base64" or "image" (PIL.Image). |
'base64'
|
Returns:
Type | Description |
---|---|
str | Image
|
The opened image. |
Source code in pixano/features/schemas/views/image.py
create_image(url, id='', item_ref=ItemRef.none(), parent_ref=ViewRef.none(), width=None, height=None, format=None, url_relative_path=None)
Create an Image
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
Path
|
The image URL. If not relative, the URL is converted to a relative path using |
required |
id
|
str
|
Image ID. |
''
|
item_ref
|
ItemRef
|
Item reference. |
none()
|
parent_ref
|
ViewRef
|
Parent view reference. |
none()
|
width
|
int | None
|
The image width. If None, the width is extracted from the image file. |
None
|
height
|
int | None
|
The image height. If None, the height is extracted from the image file. |
None
|
format
|
str | None
|
The image format. If None, the format is extracted from the image file. |
None
|
url_relative_path
|
Path | None
|
The path to convert the URL to a relative path. |
None
|
Returns:
Type | Description |
---|---|
Image
|
The created |