
SharePoint User Profiles provide a wealth of user data, but one of their most used properties is the profile picture. It can often be useful to be able to access this during custom development, and fortunately Microsoft have made it simple to access the profile picture simply via a URL.
All sites should have a built-in userphoto.aspx page that can be used to serve out user profile pictures. Accessing the page should be done using a URL of the form:
http(s)://site-url/_layouts/15/userphoto.aspx?size=L&username=target-username-here
Code language: plaintext (plaintext)
The username parameter can be the SharePoint username (e.g. i:0#.w|DOMAIN\username), a domain username (e.g. DOMAIN\username), the user’s email address, etc.
The size parameter should be S, M, or L, and will be associated with thumbnails of the following size:
- S = 48px x 48px
- M = 72px x 72px
- L = 300px x 300px
You can easily use this approach to display a user image anywhere on a SharePoint site page…
<img src="http://myspserver/sites/demo/_layouts/15/userphoto.aspx?size=M&username=i:0#.w|EXAMPLE\jsmith" alt="photo" / >
Code language: plaintext (plaintext)
NOTE: username format varies across SharePoint on-premise and SharePoint Online.