Appwrite.Services.Avatars (appwrite v1.0.0)

View Source

The Avatars service aims to help you complete everyday tasks related to your app image, icons, and avatars.

Summary

Functions

Get a favicon from a remote URL.

Get a user's gravatar based on their email address.

Get an image from a remote URL, resized and cropped to fit.

Generate a QR code image from a string.

Take a screenshot of a webpage using a headless browser.

Functions

get_browser(code, width \\ nil, height \\ nil, quality \\ nil)

@spec get_browser(String.t(), integer() | nil, integer() | nil, integer() | nil) ::
  {:ok, String.t()} | {:error, any()}

Get a browser icon image.

Parameters

  • code (required) – browser code (see Appwrite.Consts.Browser)
  • width (optional) – image width in pixels (default 100)
  • height (optional) – image height in pixels (default 100)
  • quality (optional) – JPEG quality 0–100 (default 100)

get_credit_card(code, width \\ nil, height \\ nil, quality \\ nil)

@spec get_credit_card(String.t(), integer() | nil, integer() | nil, integer() | nil) ::
  {:ok, String.t()} | {:error, any()}

Get a credit card brand logo.

Parameters

get_favicon(url)

@spec get_favicon(String.t()) :: {:ok, String.t()} | {:error, any()}

Get a favicon from a remote URL.

Parameters

  • url (required) – the website URL whose favicon to fetch

get_flag(code, width \\ nil, height \\ nil, quality \\ nil)

@spec get_flag(String.t(), integer() | nil, integer() | nil, integer() | nil) ::
  {:ok, String.t()} | {:error, any()}

Get a country flag image.

Parameters

  • code (required) – ISO 3166-1 two-letter country code
  • width (optional)
  • height (optional)
  • quality (optional)

get_gravatar(email, size \\ nil, rating \\ nil, default \\ nil)

@spec get_gravatar(String.t(), integer() | nil, String.t() | nil, String.t() | nil) ::
  {:ok, String.t()} | {:error, any()}

Get a user's gravatar based on their email address.

Parameters

  • email (required)
  • size (optional) – image size in pixels (1–2048, default 128)
  • rating (optional) – "g", "pg", "r", or "x" (default "g")
  • default (optional) – default image URL or one of the built-in defaults

get_image(url, width \\ nil, height \\ nil)

@spec get_image(String.t(), integer() | nil, integer() | nil) ::
  {:ok, String.t()} | {:error, any()}

Get an image from a remote URL, resized and cropped to fit.

Parameters

  • url (required) – the source image URL
  • width (optional)
  • height (optional)

get_initials(name \\ nil, width \\ nil, height \\ nil, background \\ nil)

@spec get_initials(
  String.t() | nil,
  integer() | nil,
  integer() | nil,
  String.t() | nil
) ::
  {:ok, String.t()} | {:error, any()}

Generate initials avatar for a name.

Parameters

  • name (optional) – full name; falls back to current user's name
  • width (optional)
  • height (optional)
  • background (optional) – hex color without #

get_qr(text, size \\ nil, margin \\ nil, download \\ nil)

@spec get_qr(String.t(), integer() | nil, integer() | nil, boolean() | nil) ::
  {:ok, String.t()} | {:error, any()}

Generate a QR code image from a string.

Parameters

  • text (required) – the text to encode
  • size (optional) – QR code size in pixels (1–1000, default 400)
  • margin (optional) – quiet-zone margin in pixels (0–10, default 1)
  • download (optional) – when true, response sets Content-Disposition: attachment

get_screenshot(url, opts \\ [])

@spec get_screenshot(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, any()}

Take a screenshot of a webpage using a headless browser.

This is a new endpoint added in Appwrite Cloud (not present in v0.2.1).

Parameters

  • url (required) – the URL to screenshot
  • opts (optional keyword list):
    • :viewport_width – viewport width in pixels (default 1280)
    • :viewport_height – viewport height in pixels (default 800)
    • :scale – device pixel ratio (default 1)
    • :theme"light" or "dark" (default "light")
    • :user_agent – custom User-Agent string
    • :fullpage – when true, captures the full scrollable page (default false)
    • :locale – browser locale, e.g. "en-US"
    • :timezone – IANA timezone, e.g. "America/New_York"
    • :latitude / :longitude – geolocation override
    • :accuracy – geolocation accuracy in metres
    • :touch – emulate touch events (true/false)
    • :permissions – list of browser permissions to grant
    • :sleep – milliseconds to wait after page load before screenshotting
    • :width – output image width in pixels
    • :height – output image height in pixels
    • :quality – JPEG/WebP quality 0–100
    • :output – output format: "jpeg", "png", or "webp"