Avatar

Base class for the avatar generator.

class DAvatar

Properties

  • style (DStyle): the style of the avatar

  • seed (str): the seed of the avatar

  • options (DOptions): the options of the avatar

  • customisations (dict): the customisations of the avatar (alias: customs)

  • url_svg (str): svg url for the avatar

  • url_webp (str): webp url for the avatar

  • url_avif (str): avif url for the avatar

  • url_png (str): png url for the avatar

  • url_jpg (str): jpg url for the avatar

  • url_jpeg (str): jpeg url for the avatar

  • url_json (str): json url for the avatar data

  • schema (dict): the dict schema of the avatar style

def __init__()

Create an avatar using this class. str(DAvatar) returns the svg url.

def __init__(self,
    style: DStyle = DStyle.random(),
    seed: str = None,
    *,
    options: DOptions = DOptions.default,
    custom: dict = None
) -> None

Returns: None: when called as string it will return the svg link

Parameter
Type
Default
Description

style

DStyle.random()

seed

None

Base string to determine the avatar.

options

DOptions.empty

General options for the avatar.

custom

None

Customisations (for the chosen style)

def edit()

Edit an already existing DAvatar.

def edit(self,
    *,
    style: DStyle = None,
    seed: str = None,
    extra_options: DOptions = None,
    blank_options: DOptions = None
) -> str # returns a string containing the svg link

Returns: str: the svg link of the edited avatar

Parameter
Type
Default
Description

style

None

seed

None

Base string to determine the edited avatar.

extra_options

None

Edit the avatar's options (old options stay, these get added or overwrite if they already existed).

blank_options

None

Edit the avatar's options (all old options get deleted and these get added, replacing the old options).

def edit_specific()

Deprecated: removed since v2.2.3

-> use DAvatar.customise() instead.

def customise()

Alias: customize()

Customise the specific options for an already existing avatar. Specific options/customisations are different for every style, so make sure to check all the possibilities here.

def customise(self,
    *,
    extra_options: dict = None,
    blank_options: dict = None
) -> str # returns a string containing the svg link

Returns: str: the svg link of the edited avatar

Parameter
Type
Default
Description

extra_options

None

Edit the avatar's options (old options stay, these get added or overwrite if they already existed).

blank_options

None

Edit the avatar's options (all old options get deleted and these get added, replacing the old options).

def save()

Save the avatar to your device.

def save(self,
    *,
    location: pathlib.Path | str = None,
    file_name: str = "dicebear_avatar",
    file_format: DFormat = DFormat.svg,
    overwrite: bool = False,
    open_after_save: bool = False
) -> str # the path where it has been saved if successful

Returns: str: the path where the avatar has been saved if successful else -1

Raises:

Parameter
Type
Default
Description

location

current directory

Location to save the avatar file.

file_name

"dicebear_avatar"

Name to give the avatar file.

file_format

DFormat.svg

Which format to use.

overwrite

False

Whether to overwrite already existing images with the given filename.

open_after_save

False

Whether to open the image after saving.

def view()

Alias: open()

Open and view a DAvatar object.

def view(self
    *,
    format: DFormat = DFormat.svg,
    use_pil: bool = True
) -> None

Returns: None

Parameter
Type
Default
Description

format

DFormat.svg

What format to use when opening the avatar image.

use_pil

True

Whether to use PIL module or something else to open the avatar.

def pillow()

Convert a DAvatar instance to a PIL.Image.Image object.

@pilcheck
def pillow(self
) -> PIL.Image.Image

Returns: PIL.Image.Image: the Image object to edit using the Pillow module

Raises: PILError: if Pillow module is not found on your device

def text()

Returns the avatar's full text/file in str format. (only useful for svg and json)

def text(self,
    format: DFormat = DFormat.svg
) -> str

Returns: str: the text of the image

Parameter
Type
Default
Description

format

DFormat.svg

What format to use.

def bytes()

Returns the avatar's bytes in io.BytesIO format (only useful for png and jpg).

Use io.BytesIO.read() to convert it to actual bytes when necessary.

def bytes(self,
    format: DFormat = DFormat.png
) -> io.BytesIO

Returns: io.BytesIO: the bytes of the image

Parameter
Type
Default
Description

format

DFormat.png

What format to use.

Last updated