imgutils.resource.background

Overview:

Get background images.

These resources are hosted on deepghs/anime-bg, which is based on skytnt/anime-segmentation.

../../_images/background_full.plot.py.svg

BackgroundImageSet

class imgutils.resource.background.BackgroundImageSet(width: float | None = None, height: float | None = None, strict_level: float = 1.5, min_selected: int = 5, min_width: int | None = None, min_height: int | None = None, min_resolution: int | None = None)[source]
__init__(width: float | None = None, height: float | None = None, strict_level: float = 1.5, min_selected: int = 5, min_width: int | None = None, min_height: int | None = None, min_resolution: int | None = None)[source]

Initialize a BackgroundImageSet instance.

Parameters:
  • width (Optional[float]) – The desired width of background images. (default: None)

  • height (Optional[float]) – The desired height of background images. (default: None)

  • strict_level (float) – The strictness level for selecting images. (default: 1.5)

  • min_selected (int) – The minimum number of images to consider for selection. (default: 5)

  • min_width (Optional[int]) – The minimum width of background images to consider. (default: None)

  • min_height (Optional[int]) – The minimum height of background images to consider. (default: None)

  • min_resolution (Optional[int]) – The minimum resolution of background images to consider. (default: None)

get_image(filename: str) Image[source]

Get the PIL Image object of a background image by filename.

Parameters:

filename (str) – The filename of the background image.

Returns:

The PIL Image object of the background image.

Return type:

Image.Image

get_image_file(filename: str) str[source]

Get the local file path of a background image by filename.

Parameters:

filename (str) – The filename of the background image.

Returns:

The local file path of the background image.

Return type:

str

list_image_files() List[str][source]

Get a list of filenames of background images.

Returns:

A list of filenames of background images.

Return type:

List[str]

random_image() Image[source]

Get the PIL Image object of a randomly selected background image.

Returns:

The PIL Image object of a randomly selected background image.

Return type:

Image.Image

random_image_file() str[source]

Get the filename of a randomly selected background image.

Returns:

The filename of a randomly selected background image.

Return type:

str

list_bg_image_files

imgutils.resource.background.list_bg_image_files() List[str][source]

Get a list of filenames of background images.

Returns:

A list of filenames of background images.

Return type:

List[str]

Examples::
>>> from imgutils.resource import list_bg_image_files
>>>
>>> files = list_bg_image_files()
>>> type(files)
<class 'list'>
>>> len(files)
8057
>>> files[:5]
['000000.jpg', '000001.jpg', '000002.jpg', '000003.jpg', '000004.jpg']

get_bg_image_file

imgutils.resource.background.get_bg_image_file(filename: str) str[source]

Get the local file path of a background image by filename.

Parameters:

filename (str) – The filename of the background image.

Returns:

The local file path of the background image.

Return type:

str

Examples::
>>> from imgutils.resource import get_bg_image_file
>>>
>>> get_bg_image_file('000001.jpg')
'/home/user/.cache/dghs-imgutils/bg/000001.jpg'

get_bg_image

imgutils.resource.background.get_bg_image(filename) Image[source]

Get the PIL Image object of a background image by filename.

Parameters:

filename (str) – The filename of the background image.

Returns:

The PIL Image object of the background image.

Return type:

Image.Image

Examples::
>>> from imgutils.resource import get_bg_image
>>>
>>> get_bg_image('000001.jpg')
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2400x1600 at 0x7FEB86ED5160>

random_bg_image_file

imgutils.resource.background.random_bg_image_file() str[source]

Get the filename of a randomly selected background image.

Returns:

The filename of a randomly selected background image.

Return type:

str

Examples::
>>> from imgutils.resource import random_bg_image_file
>>>
>>> random_bg_image_file()
'/home/user/.cache/dghs-imgutils/bg/003258.jpg'

random_bg_image

imgutils.resource.background.random_bg_image() Image[source]

Get the PIL Image object of a randomly selected background image.

Returns:

The PIL Image object of a randomly selected background image.

Return type:

Image.Image

Examples::
>>> from imgutils.resource import random_bg_image
>>>
>>> random_bg_image()
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=400x400 at 0x7FEB86A748B0>