How to Get Gravatar Image Using PHP

Get Gravatar Image using PHP, We can get this by simply generating gravatar URL with email id. Then use this URL in image source attribute to display gravatar image in the browser.

First of all, store email address in a variable. Remove any spaces in email address using trim PHP function. And convert all the letters to lower case if any by using strtolower PHP function. Then convert this email string into md5 hash using md5 PHP function.

Add this md5 hash after the URL “https://www.gravatar.com/avatar/”your-md5-hash-here And if you want to get image with any custom sizes add this query term after md5 hash (?s=150) Use this above URL in source attribute of the image tag.

Assign your email id into a variable.

Then convert this email id into md5 hash using these functions.

Set image size.

Generate gravatar URL.

Open this URL in new tab to check gravatar image. Or else yo can echo this url inside image tag source attribute.

Complete Code

If you have any problem assembling above code, you can use this below code.

If you still have any problem, let me know through comment form below.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe