search
Homephp教程php手册php获取QQ头像并显示的方法,php获取qq头像

php获取QQ头像并显示的方法,php获取qq头像

本文实例讲述了php获取QQ头像并显示的方法。分享给大家供大家参考。具体分析如下:

最近看到博客留言的头像有点别扭,因为游客的头像都是同一个头像,看着不是很舒服。虽然现在绝大多数的主题集成了Gavatar头像功能,先不说gavatar被墙的问题,我自己现在都没弄个gavatar头像.

因为我登陆了几次,连接速度巨慢,所以我就放弃了,当然留言插件也不胜枚举,比如现在比较火的多说,但对于没有注册多说的朋友,头像仍是个问题,对于多说的社交账号绑定,我测试多次,QQ,人人这些主流平台的绑定经常出错,而且有的朋友讨厌繁琐的授权.

鉴于此,我在想一个大众化的,比较简单的方法,我想到的是对于没有头像的朋友调用其QQ头像,因为QQ现在至少是人手一个,所以只需要留言时填写QQ号,然后调用其头像,这样一来就方便多了.

首先是获取QQ的头像了,这也是这个想法的第一步,即今天的主题.

第一种方法,代码如下:

复制代码 代码如下:

$qq = 123456789;
echo 'php获取QQ头像并显示的方法,php获取qq头像';
?>


第二种方法,代码如下:

复制代码 代码如下:

$qq = 552452006;
 
$src = 'http://q1.qlogo.cn/g?b=qq&nk=' . $qq . '&s=100&t=' . time();
 
header('Content-type: image/png');
 
$res = imagecreatefromstring(file_get_contents($src));
imagepng($res);
 
imagedestroy($res);
?>


这两种方法的区别:

第一种方法的优点是可以输出头像的原图,如果你的头像是动态的gif,那么输出的也是动态图,缺点是速度比较慢,不适合作为调用头像的方法.

第二种方法的优点是相比第一种速度比较快,但只抓取头像的静态图,不会显示动态头像,比较适合作为调用头像的方法.

希望本文所述对大家的php程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.