avatar.utils

Define the Avatar utilities.

Copyright (C) 2021 Gitcoin Core

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

build_random_avatar

build_random_avatar(override_skin_tone=None, override_hair_color=None, add_facial_hair=True)

Build an random avatar payload using context properties

handle_avatar_payload

handle_avatar_payload(body)

Handle the Avatar payload.

get_temp_image_file

get_temp_image_file(image)

Fetch an image from a remote URL and hold in temporary IO.

Args: url (str): The remote image URL.

Returns: BytesIO: The temporary BytesIO containing the image.

convert_img

convert_img(obj)

Convert the provided buffer to another format.

Args: obj (File): The File/ContentFile object. input_fmt (str): The input format. Defaults to: svg. output_fmt (str): The output format. Defaults to: png.

Exceptions: Exception: Cowardly catch blanket exceptions here, log it, and return None.

Returns: BytesIO: The BytesIO stream containing the converted File data. None: If there is an exception, the method returns None.

convert_wand

convert_wand(img_obj, input_fmt='png', output_fmt='svg')

Convert an SVG to another format.

Args: img_obj (File): The PNG or other image File/ContentFile. input_fmt (str): The input format. Defaults to: png. output_fmt (str): The output format. Defaults to: svg.

Returns: BytesIO: The BytesIO stream containing the converted File data. None: If there is an exception, the method returns None.