How to obtain and display the QQ profile picture in php

Source: Internet
Author: User

How to obtain and display the QQ profile picture in php

Recently, the headers of blog posts are a bit awkward, because they all share the same profile picture, which is not very comfortable. Although most of the themes are now integrated with the Gavatar Avatar function, I did not get a gavatar avatar myself, not to mention the problem of gavatar being walled.

Because I have logged on several times and the connection speed is very slow, I gave up. Of course, there are too many message plug-ins to list. For example, it's a bit popular to say it now, but for friends who haven't registered many words, the Avatar is still a problem. For more social account binding, I have tested it for many times. QQ and Renren often encounter errors in binding to mainstream platforms, and some friends hate tedious authorization.

In view of this, I am thinking about a popular and simple method. I think of a friend who does not have a profile picture to call his QQ profile picture, because QQ is at least one person now, therefore, you only need to enter the QQ number when leaving a message, and then call its avatar, which makes it much easier.

The first step is to get QQ's profile picture, which is the first step of this idea, that is, today's topic.

The code for the first method is as follows:

 

The Code is as follows:

<? Php
$ Qq = 123456789;
Echo ' ';
?>


The code for the second method is as follows:

The Code is as follows:

<? Php
$ 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 );
?>


The difference between the two methods:

 

The advantage of the first method is that you can output the source image of the Avatar. If your avatar is a dynamic gif, the output is also a dynamic image. The disadvantage is that the speed is slow, this method is not suitable for calling the Avatar.

The advantage of the second method is that it is faster than the first method, but it only captures the static graph of the Avatar and does not display the dynamic avatar. It is more suitable for calling the Avatar method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.