DgsGIFGetSize
Jump to navigation
Jump to search
Returns the dimensions (width and height) of a GIF element created using dgsCreateGIF. The values correspond to the original size extracted from the GIF file during loading.
Syntax
int int dgsGIFGetSize( element gif )
Required Arguments
- gif: The dgs-dxgif type element you want to get the size of.
Returns
Returns two integers corresponding to width and height
Example
-- This script should be executed on the client-side
-- Import the DGS functions to use them from another resource
local DGS = exports.dgs
-- 1. Load the GIF from a file within your resource
local myAnimatedGif = DGS.dgsCreateGIF("files/loading.gif")
-- 2. Check if the GIF was loaded successfully before proceeding
if myAnimatedGif then
-- 3. Use dgsGIFGetSize to get the width and height of the loaded GIF
local width, height = DGS.dgsGIFGetSize(myAnimatedGif)
-- 4. Display the dimensions in the chat to confirm the result
outputChatBox(string.format("The loaded GIF has the dimensions: %d width by %d height.", width, height))
-- 5. Practical example: Create a DGS image in the center of the screen
-- using the 'width' and 'height' we just obtained so the size is perfect.
local screenW, screenH = guiGetScreenSize()
local posX = screenW / 2 - width / 2
local posY = screenH / 2 - height / 2
local gifImage = DGS.dgsCreateImage(posX, posY, width, height, myAnimatedGif, false)
-- Start the GIF's animation
DGS.dgsGIFPlay(myAnimatedGif)
else
-- Inform the user if the GIF was not found or if an error occurred during loading
outputChatBox("Error: Could not load the GIF file.", 255, 0, 0)
end