Gravatar returns wrong file extension

67 views Asked by At

I'm trying to get JPG images from Gravatar by adding .jpg at the end of the hash, like this: https://www.gravatar.com/avatar/00000000000000000000000000000000.jpg?d=wavatar&f=y

However, if I save it to the disk like this:

file_put_contents($path, file_get_contents('https://www.gravatar.com/avatar/00000000000000000000000000000000.jpg?d=wavatar&f=y'));

Or if I save it directly from the browser to my computer I notice that the file is in fact a PNG image.

Why is that?
Am I missing something?

Thks!

1

There are 1 answers

0
shin On

That link will give you png file even you have jpg at the end. If you want a jpeg image, try this in your php.

echo '<img src="https://www.gravatar.com/avatar/'. md5(strtolower("[email protected]")).'"
class="img-circle" alt="User Image">';

Code at phponline and download this jpeg image.