dxConvertPixels | Multi Theft Auto: Wiki Skip to content

dxConvertPixels

Client-side
Server-side
Shared

This function converts pixels from one format to another.

Syntax

string|false dxConvertPixels ( ​string pixels, ​string newFormat, [ ​int quality = 80 ] )
Required arguments
  • pixels: The pixels to convert the format of.
  • newFormat: The new format required.
    • plain
    • png
    • jpeg
Optional arguments

Note: when using optional arguments, you might need to supply all arguments before the one you wish to use.

  • quality (default: 80): The quality of the returned pixels if the new format is jpeg.

Returns

Returns a copy of the pixels in the new format, or false if invalid arguments were passed to the function.

  • string|false: pixels

Code Examples

client

The code opens an image, read its pixels, convert the pixels to PNG, and then save it.

addEventHandler('onClientResourceStart', resourceRoot, function()
local img = fileOpen('img.jpg')
local pixels = fileRead(img, fileGetSize(img))
local pngPixels = dxConvertPixels(pixels, 'png')
local newImg = fileCreate('img.png')
fileWrite(newImg, pngPixels)
fileClose(newImg)
fileClose(img)
end)