image
¶
Image processing and manipulation.
get_img_ext
¶
Get the extension of an image from a byte string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
bytes
|
A byte string representing an image. |
required |
Returns:
Type | Description |
---|---|
str
|
The extension of the image file. |
Source code in src/images_upload_cli/image.py
11 12 13 14 15 16 17 18 19 20 21 22 |
|
get_font
¶
get_font(size: int = 14) -> FreeTypeFont
Get font for thumbnail captions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
The size of the font. Defaults to 14. |
14
|
Returns:
Type | Description |
---|---|
FreeTypeFont
|
ImageFont.FreeTypeFont: Represents the font. |
Source code in src/images_upload_cli/image.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
search_font
¶
search_font(fonts: list[str], size: int = 14) -> FreeTypeFont
Attempt to retrieve a TTF font from the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fonts |
list[str]
|
A list of font names to search for. |
required |
size |
int
|
The font size. Defaults to 14. |
14
|
Returns:
Type | Description |
---|---|
FreeTypeFont
|
ImageFont.FreeTypeFont: Represents the font. |
Raises:
Type | Description |
---|---|
GetEnvError
|
If none of the default fonts are found. |
Source code in src/images_upload_cli/image.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
make_thumbnail
¶
Generate thumbnail for the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
bytes
|
The input image in bytes format. |
required |
font |
FreeTypeFont
|
The font to be used for the text caption. |
required |
size |
tuple[int, int]
|
The desired size of the thumbnail image. Defaults to (300, 300). |
(300, 300)
|
Returns:
Type | Description |
---|---|
bytes
|
The modified image in bytes format. |
Source code in src/images_upload_cli/image.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|