Building Twitter profile image url with Twitter user id

Introducing the easiest way to get a Twitter Profile Image without using the Twitter API:

Using http://avatars.io/

As @AlexB, @jfred says, it doesn't work at all on mobile devices.

And it's quite a hard way to get a redirected URL using common frameworks like PHP or JavaScript in your single page.

Simply call http://avatars.io/twitter/ruucm at your image tag, like

<img src="https://avatars.io/twitter/ruucm" alt="twt_profile" border="0" width="259"/>

I've tested it with Angular 2+ and it works without any problem.


As of February 20, 2020 it would appear this is impossible. Using the API seems like the only option at the moment. For more info see my question I've opened here: Twitter profile picture images now blocked on most domains


With API 1.1 you can achieve this using these URLs:

  • https://twitter.com/[screen_name]/profile_image?size=mini
  • https://twitter.com/[screen_name]/profile_image?size=normal
  • https://twitter.com/[screen_name]/profile_image?size=bigger
  • https://twitter.com/[screen_name]/profile_image?size=original

Official twitter documentation Profile Images and Banners

Example

https://twitter.com/TwitterEng/profile_image?size=original

will redirect to

https://pbs.twimg.com/profile_images/875168599299637248/84CkAq6s.jpg

As of June 2020, both the accepted answer and avatars.io no longer work. Here are two alternatives:

unavatar.io

(formerly unavatar.now.sh)

Unavatar can get pictures from quite a few different places including Twitter. Replace [screen_name] in the URL below with the Twitter username you want.

<img src="https://unavatar.io/twitter/[screen_name]" />

For example:

<img src="https://unavatar.io/twitter/jack" width="100" height"100" />

If the demo above ever stops working, it's probably because unavatar.io is no longer available.

Unavatar is open source though, so if it does go down, you can deploy it yourself from the GitHub repo — it even has "Deploy to Vercel/Heroku" buttons. The code to fetch Twitter avatars specifically is here, so you could also use that as part of your own backend.


twivatar.glitch.me

⚠️ As of July 2021 this option no longer works, see the one above instead!

If you want an alternative, you can also use twivatar.glitch.me. Replace [screen_name] in the URL below with the Twitter username you want.

<img src="https://twivatar.glitch.me/[screen_name]" />

For example:

<img src="https://twivatar.glitch.me/jack" width="100" height"100" />

If the demo above ever stops working, it's probably because twivatar.glitch.me is no longer available.

By the way, I didn't build either of these services, they were both made by other people.

Tags:

Twitter