Fivemanage SDK for FiveM
Working with Images

Working with Images

This section provides examples of how to use the takeImage and takeServerImage exports on the client and server sides, respectively.

Examples are provided in both Lua and JavaScript. TypeScript developers can refer to the type annotations provided in the function definitions for guidance on the expected argument and return types.

Client Exports

Function Definition:

takeImage(metadata?: Record<string, unknown>): Promise<{ url: string }>

Lua Example:

local imageData = exports.fmsdk:takeImage()
 
-- With metadata
local imageData = exports.fmsdk:takeImage({
    name = "My image",
    description = "This is my image",
    -- or any other field you want
})
 
print(imageData.url)

JavaScript Example:

exports.fmsdk.takeImage().then((imageData) => {
  console.log(imageData.url);
});
 
// With metadata
exports.fmsdk
  .takeImage({
    name: "My image",
    description: "This is my image",
    // or any other field you want
  })
  .then((imageData) => {
    console.log(imageData.url);
  });

Server Exports

Function Definition:

takeServerImage(playerSource: string | number, metadata?: Record<string, unknown>, timeout?: number): Promise<{ url: string }>

Lua Example:

local imageData = exports.fmsdk:takeServerImage(playerSource)
 
-- With metadata
local imageData = exports.fmsdk:takeServerImage(playerSource, {
    name = "My image",
    description = "This is my image",
    -- or any other field you want
})
 
print(imageData.url)
 
-- With timeout
local success, imageData = pcall(function()
    return exports.fmsdk:takeServerImage(source, {
        name = 'My image',
        description = 'This is my image',
    }, 10000)
end)
 
if success then
    print(imageData.url)
else
    error('We are unable to capture screenshot of the player.')
end

JavaScript Example:

exports.fmsdk.takeServerImage(playerSource).then((imageData) => {
  console.log(imageData.url);
});
 
// With metadata
exports.fmsdk
  .takeServerImage(playerSource, {
    name: "My image",
    description: "This is my image",
    // or any other field you want
  })
  .then((imageData) => {
    console.log(imageData.url);
  });