ImageSingle
ClassSource
ImageSingle(
img: str | PathLike[str] | IO[bytes] | Image | Self,
fmt: str | ImageFormat | None = None,
)
The basic one-layer style of image.
Add some extended method for providing extra image processing features.
Arguments
Requires
| Name | Type | Required | |
|---|---|---|---|
img | str | PathLike[str] | IO[bytes] | Image | Self | The image used for initializing this instance. It can be a file path, a file-like object, an image object or this kind of object. | |
fmt | str | ImageFormat | None | The format to be used for saving this image. If not specified, will try to automatically infer the format. |
Methods
add_background
v_1: Self = self.add_background(color: str | tuple[float, ...] = "#1b2838")
Add a background to the image.
If the current image mode is not RGBA, the output image mode will be converted to RGB automatically.
Requires
| Name | Type | Required | |
|---|---|---|---|
color | str | tuple[float, ...] | The color of the added background. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The modified image. |
blur
v_1: Self = self.blur(blur_size: int, dil_size: int | None = None)
Make the image blured.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
blur_size | int | The size of blur filter. | |
dil_size | int | None | The size of the dilation. If not specified, it will be the same as blur_size. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The modified image. |
convert
v_1: Self = self.convert(mode: str)
Convert the image mode.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
mode | str | The mode of the converted image. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The converted image. |
copy
v_1: Self = self.copy()
Get a copy of this object.
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The copied image. |
crop
v_1: Self = self.crop(
size: tuple[int | None, int | None], anchor: str | ImageAnchor = ImageAnchor.center
)
Crop this image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
size | tuple[int | None, int | None] | The size of the cropped image. If this size is larger than the original size, the image mode will be converted to RGBA. If a size is value | |
anchor | str | ImageAnchor | The anchor where we set for cropping the image. For example, when this anchor is "center", will crop the image for four sides. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The cropped image. |
quantize
v_1: Self = self.quantize(n: int = 16)
Quantize the image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
n | int | The number of colors used during the quantization. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The converted image. |
resize
v_1: Self = self.resize(size: tuple[None, int], resample: int | None = None)
v_1: Self = self.resize(size: tuple[int, None], resample: int | None = None)
v_1: Self = self.resize(size: tuple[int, int], resample: int | None = None)
Resize this image.
This operation is non-inplace.
Arguments (ver. 1)
Resize this image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
size | tuple[None, int] | The size of the resized image. Only the target height is provided. Will resize the image while preserving the w/h ratio. | |
resample | int | None | The resample method specified by If not specified, will select the resample method automatically:
|
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The resized image. |
Arguments (ver. 2)
Resize this image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
size | tuple[int, None] | The size of the resized image. Only the target width is provided. Will resize the image while preserving the w/h ratio. | |
resample | int | None | The resample method specified by If not specified, will select the resample method automatically:
|
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The resized image. |
Arguments (ver. 3)
Resize this image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
size | tuple[int, int] | The size of the resized image. | |
resample | int | None | The resample method specified by If not specified, will select the resample method automatically:
|
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The resized image. |
save
self.save(
fobj: str | PathLike[str] | IO[bytes],
quality: str | ImageQuality = ImageQuality.high,
)
Save the image as a file.
Before saving the image, this method will run optimizations corresponding to the saving format.
Requires
| Name | Type | Required | |
|---|---|---|---|
fobj | str | PathLike[str] | IO[bytes] | The file path of file-like object of the output file. | |
quality | str | ImageQuality | The quality of the image to be saved. |
save_steam_screenshot
self.save_steam_screenshot(
folder_path: str | PathLike[str],
file_name: str,
quality: str | ImageQuality = ImageQuality.high,
skip_thumbnails: bool = False,
)
Save the image as a Steam screenshot.
When using this method to save the image, we will create a "thumbnails" folder where we save the image, and save the small version (thumbnail image) in the "thumbnails" folder.
Requires
| Name | Type | Required | |
|---|---|---|---|
folder_path | str | PathLike[str] | The path of the folder where we save the image. | |
file_name | str | The name of the saved screenshot file. | |
quality | str | ImageQuality | The quality of the image to be saved. | |
skip_thumbnails | bool | A flag. If specified, will not save thumbnails. |
to_lossless
v_1: Self = self.to_lossless()
Convert the format of this image to the lossless type.
This operation is non-inplace.
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The converted image. |
to_lossy
v_1: Self = self.to_lossy()
Convert the format of this image to the lossy type.
This operation is non-inplace.
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The converted image. |
to_palette
v_1: Self = self.to_palette(n: int | None = None)
Quantize the image and convert the image mode to the palette-based mode. Note that this method will convert the image to the RGB image.
This operation is non-inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
n | int | None | The number of colors used in the palette. If not specified, will use Image.Palette.WEB palette. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The converted image. |
Properties
height
height: int = self.height
The image height.
size
size: tuple[int, int] = self.size
The image (width, height).
width
width: int = self.width
The image width.