steamworks.getUserImageInfo()

Type Function
Return value ImageInfo
Revision Release 2024.3703
Keywords steam, steamworks, getUserImageInfo
See also steamworks.newImageRect()
steamworks.newTexture()
steamworks.*

Overview

Returns an ImageInfo object. This provides information about one user avatar image such as its pixel width, pixel height, and unique image handle. This object's imageHandle property is needed to load the image via the steamworks.newImageRect() and steamworks.newTexture() functions.

Gotchas

This function will typically return nil when attempting to fetch information about a 184×184 pixel "largeAvatar" image. This is because the Steam client does not normally cache these large images.

Additionally, this function will always return nil in these cases:

Syntax

steamworks.getUserImageInfo( type [, userSteamId] )
type (required)

String. Unique name of the image to fetch from the user. This must be one of the following:

Type Pixel Size (w×h)
"smallAvatar" 32×32
"mediumAvatar" 64×64
"largeAvatar" 184×184
userSteamId (optional)

String. Unique string ID of the user. The ID will default to the current user if this argument is not provided.

Example

local steamworks = require( "plugin.steamworks" )

-- Forward-reference the last displayed avatar image
local avatarImage

-- Displays the currently logged in user's avatar image
local function displaySteamUserAvatar()
    -- Fetch information about the user's medium-sized avatar image
    local imageInfo = steamworks.getUserImageInfo( "mediumAvatar" )
    if ( imageInfo == nil ) then
        -- Image is not available yet; wait for a "userInfoUpdate" event
        return
    end

    -- Display the avatar image
    local newAvatarImage = steamworks.newImageRect( imageInfo.imageHandle, 64, 64 )
    if ( newAvatarImage == nil ) then
        return
    end
    newAvatarImage.x = display.contentCenterX
    newAvatarImage.y = display.contentCenterY

    -- Remove the last displayed avatar image, if it exists
    if ( avatarImage ) then
        avatarImage:removeSelf()
    end

    -- Store a reference to the new avatar image
    avatarImage = newAvatarImage
end

-- Attempt to show the currently logged in user's avatar image on startup
-- Note that this will likely fail on the first app launch by the Steam client
displaySteamUserAvatar()

-- Called when a Steam user's information/avatar has changed
local function onSteamUserInfoUpdated( event )
    -- Display current user's medium-sized avatar if it changed or loaded for the first time
    if ( ( event.userSteamId == steamworks.userSteamId ) and event.mediumAvatarChanged ) then
        displaySteamUserAvatar()
    end
end
steamworks.addEventListener( "userInfoUpdate", onSteamUserInfoUpdated )