Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Gravatar

I am using this ( https://github.com/creativeorange) package. My controller code is like below.

$data['gravatar'] = (!empty(auth()->user()->email)) ? Gravatar::fallback(url('images/user.jpg'))->get(auth()->user()->email) : null;

dd($data['gravatar']);

I am getting output like below

"https://secure.gravatar.com/avatar/a516098e1de8e2756fa4bf045c7a4cb2.jpg?s=150&d=http%3A%2F%2F127.0.0.1%3A8000%2Fimages%2Fuser.jpg&r=g"

But I would like to get output like below

http://127.0.0.1:8000/images/user.jpg
0 likes
7 replies
afoysal's avatar

Thanks @automica . I found below words here (https://en.gravatar.com/site/implement/images/)

If you'd prefer to use your own default image (perhaps your logo, a funny face, whatever), then you can easily do so by supplying the URL to an image in the d= or default= parameter. The URL should be URL-encoded to ensure that it carries across correctly, for example:

<img src="https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fexample.com%2Fimages%2Favatar.jpg" />

I am getting HTML like below

<img id="userImg" class="userImg" src="https://secure.gravatar.com/avatar/a516098e1de8e2756fa4bf045c7a4cb2.jpg?s=150&amp;d=http%3A%2F%2F127.0.0.1%3A8000%2Fimages%2Fuser.jpg&amp;r=g" alt="user">
automica's avatar

@afoysal that looks like its returning a gravatar because you have one set. The only difference is the Gravatar is returning the 's' value which relates to the size.

Did the code I provide not get the result you wanted?

1 like
afoysal's avatar

Thanks @automica . Actually I would like to find out where is the issue using my code. It is not returning a gravatar. It is returning what inside alt attribute.

automica's avatar

@afoysal if I post the following:

http://secure.gravatar.com/avatar/a516098e1de8e2756fa4bf045c7a4cb2.jpg?s=150&d=http%3A%2F%2F127.0.0.1%3A8000%2Fimages%2Fuser.jpg&r=g

into my browser I see the blue gravatar image eg

http://secure.gravatar.com/avatar/a516098e1de8e2756fa4bf045c7a4cb2.jpg

however if I put

https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fexample.com%2Fimages%2Favatar.jpg

into my browser, it resolves to

https://i0.wp.com/example.com/images/avatar.jpg?ssl=1

and throws an error that the image can't be found

As thats a non public image, I tried again with a remote image I know exists

eg

https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fbrightstorm.co.uk%2Fassets%2Fimg%2Flogo.png

and that resolves to

https://i2.wp.com/brightstorm.co.uk/assets/img/logo.png?ssl=1

so I hazard your issue is that your images are being served from localhost and so the remote side at Gravatar can't parse and display them.

2 likes
automica's avatar
automica
Best Answer
Level 54

@afoysal if you use the fallback method you won't be able to display images served from your development environment until they are publicly available.

gravatar grabs your public image and then serves it from its own https domain rather that defaulting to the path you gave it.

if you use the code I posted in my first comment then you should be able to use your local image if the remote gravatar doesn't exist and that will provide images for you as you develop your project.

1 like

Please or to participate in this conversation.