avatar.utils

Define the Avatar utilities.

Copyright (C) 2018 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/.

get_svg_templates

get_svg_templates()

Get the SVG templates for all avatar categories.

handle_avatar_payload

handle_avatar_payload(request)

Handle the Avatar payload.

get_temp_image_file

get_temp_image_file(url)

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.

get_github_avatar

get_github_avatar(handle)

Pull the latest avatar from Github and store in Avatar.png.

Returns: bool: Whether or not the Github avatar was updated.

convert_img

convert_img(obj, input_fmt='svg', output_fmt='png')

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.