Simply Ruby Gem to generate Gravatar tags
A simple and up-to-date Ruby gem for generating Gravatar image URLs and HTML tags. Easily add Gravatar support to your Ruby or Rails applications with this lightweight library.

Installation
To install the rb-gravatar gem, run:
gem install rb-gravatar
Or add it to your Gemfile:
gem 'rb-gravatar'
Then run:
bundle install
Usage
Basic Usage
Generate Only the Gravatar Image URL:
The Gravatar.src method returns the Gravatar URL for a given email, size, and optional default image.
require 'rb-gravatar'
puts Gravatar.src('you@you.com')
puts Gravatar.src('you@you.com', 32)
puts Gravatar.src('you@you.com', 32, 'https://example.com/image.png')
Generate the Gravatar Image Tag:
The Gravatar.tag method returns a complete HTML <img> tag for embedding the Gravatar image in a web page, including optional alt text.
puts Gravatar.tag('you@you.com')
puts Gravatar.tag('you@you.com', 32, 'https://example.com/image.png', 'User avatar')
Using with Rails
When using Gravatar.tag in Rails views, Rails escapes HTML by default. To render the HTML tag unescaped, wrap it in the Rails raw helper:
<%= raw Gravatar.tag('you@you.com', 64, nil, 'Profile Picture') %>
Parameters
Gravatar.src(email_address, size = 64, default_image_url = nil): Generates the Gravatar image URL.
email_address: The email address used to generate the Gravatar.
size: The desired image size (between 1 and 2048 pixels).
default_image_url: The URL of the default image to show if the user has no Gravatar.
Gravatar.tag(email_address, size = 64, default_image_url = nil, alt_text = ''): Generates the complete HTML <img> tag.
email_address: The email address used to generate the Gravatar.
size: The desired image size.
default_image_url: URL of the default image.
alt_text: Alternative text for the image.
DNS Prefetch
For faster image loading, add a DNS prefetch tag to your page headers:
<%= Gravatar.prefetch_dns %>
This inserts:
<link rel="dns-prefetch" href="//gravatar.com">
License
Please see LICENSE for licensing details.
Author
github.com/sn