Functions for generating random Gravatar URLs.
Provides utilities to generate Gravatar image and profile URLs with customizable size, fallback type, rating, and format options, based on the Gravatar API.
Summary
Functions
Returns the default image size in pixels.
Generates a Gravatar image URL.
Returns the list of all valid fallback type atoms.
Generates a Gravatar profile URL.
Generates a Gravatar image URL with randomly selected size and fallback type.
Returns the valid image size range.
Types
@type email() :: String.t() | nil
Email address.
Functions
@spec default_size() :: pos_integer()
Returns the default image size in pixels.
Examples
iex> NeoFaker.Gravatar.default_size()
80
Generates a Gravatar image URL.
Returns the Gravatar avatar URL for the given email address. If nil is passed,
a random email is used.
Parameters
email- Email address to hash. Ifnil, generates a random email.opts- Keyword list of options::size- Image size in pixels (1–2048). Defaults to80.:fallback- Default image type. Defaults to:identicon.:rating- Maximum content rating. Defaults tonil(no restriction).:force_default- Whentrue, always returns the fallback image. Defaults tofalse.
Options
The values for :fallback can be:
:identicon- Geometric pattern based on email hash (default).:monsterid- Generated monster image.:wavatar- Generated face image.:robohash- Generated robot image.:retro- 8-bit arcade-style pixelated face.:blank- Transparent PNG.:"404"- HTTP 404 response.- Custom
http://orhttps://URL string.
The values for :rating can be:
:g- Suitable for all audiences.:pg- May contain mild profanity or suggestive content.:r- May contain harsh profanity, violence, or nudity.:x- May contain explicit sexual imagery or extreme violence.
Examples
iex> NeoFaker.Gravatar.display()
"https://gravatar.com/avatar/<hashed_email>?d=identicon&s=80"
iex> NeoFaker.Gravatar.display("john.doe@example.com", size: 100)
"https://gravatar.com/avatar/<hashed_email>?d=identicon&s=100"
iex> NeoFaker.Gravatar.display("john.doe@example.com", fallback: :monsterid)
"https://gravatar.com/avatar/<hashed_email>?d=monsterid&s=80"
iex> NeoFaker.Gravatar.display("user@test.com", rating: :pg)
"https://gravatar.com/avatar/<hashed_email>?d=identicon&s=80&r=pg"
iex> NeoFaker.Gravatar.display("user@test.com", force_default: true)
"https://gravatar.com/avatar/<hashed_email>?d=identicon&s=80&f=y"
@spec fallback_types() :: [atom()]
Returns the list of all valid fallback type atoms.
Examples
iex> NeoFaker.Gravatar.fallback_types()
[:identicon, :monsterid, :wavatar, :robohash, :retro, :blank, :"404"]
Generates a Gravatar profile URL.
Returns the Gravatar profile page URL for the given email address. If nil is
passed, a random email is used.
Parameters
email- Email address to hash. Ifnil, generates a random email.opts- Keyword list of options::format- Response format. Defaults to:html.
Options
The values for :format can be:
:html- HTML profile page (default).:json- JSON API endpoint.:xml- XML API endpoint.:php- PHP serialized data endpoint.:vcf- vCard/VCF endpoint.:qr- QR code image endpoint.
Examples
iex> NeoFaker.Gravatar.profile()
"https://gravatar.com/<hash>"
iex> NeoFaker.Gravatar.profile("user@example.com", format: :json)
"https://gravatar.com/<hash>.json"
iex> NeoFaker.Gravatar.profile(nil, format: :xml)
"https://gravatar.com/<hash>.xml"
@spec random() :: String.t()
Generates a Gravatar image URL with randomly selected size and fallback type.
Examples
iex> NeoFaker.Gravatar.random()
"https://gravatar.com/avatar/<hash>?d=monsterid&s=150"
iex> NeoFaker.Gravatar.random()
"https://gravatar.com/avatar/<hash>?d=wavatar&s=64"
@spec size_range() :: Range.t()
Returns the valid image size range.
Examples
iex> NeoFaker.Gravatar.size_range()
1..2048