2017-01-02 45 views
1

我试图通过在哈希的末尾添加.JPG,像这样得到的Gravatar JPG图片: https://www.gravatar.com/avatar/00000000000000000000000000000000.jpg?d=wavatar&f=y的Gravatar返回错误的文件扩展名

但是,如果我把它保存到这样的盘:

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

或者,如果我直接从浏览器保存到我的电脑,我注意到该文件实际上是一个PNG图像。

这是为什么?
我错过了什么吗?

Thks!

+0

哦...好吧,那就是API给出的。那么,为什么不使用gd将它转换成JPG呢? –

回答

1

该链接将给你PNG文件,即使你有JPG结尾。如果你想要一个jpeg图像,请在你的php中试试。

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

代码在phponline和下载this jpeg image