DgsCreateSVG: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (related functions)
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Client function}}
__NOTOC__
Creates an svg from size (blank document), filepath or raw data , similar to [[svgCreate]].  
Creates an svg from size (blank document), filepath or raw data , similar to [[svgCreate]].  
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
svg dgsCreateSVG(int width, int height,string pathORrawData)
svg dgsCreateSVG ( int width, int height [, string pathORrawData ] )
</syntaxhighlight>  
</syntaxhighlight>  
===Required Arguments===
===Required Arguments===
Line 12: Line 14:
===Returns===
===Returns===
* Returns an [[svg]] if created successfully, ''false'' otherwise.
* Returns an [[svg]] if created successfully, ''false'' otherwise.
==Example==
==Example==
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
loadstring(exports.dgs:dgsImportFunction())() -- load dgs functions using loadstring
loadstring(exports.dgs:dgsImportFunction())() -- load dgs functions using loadstring.
-- Create circle rowData and apply it to variable
local rawSvgData = [[
    <svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
        <circle cx="250" cy="250" r="250" fill="#0fc0fc" />
    </svg>
]]


function init()
local svg = dgsCreateSVG(500,500) -- Create the SVG .
    -- Create an SVG containing a circle, using the raw XML data above
local svgDoc = dgsSVGGetDocument(svg) -- Get the SVG Document so you can modify it .
    svg = dgsCreateSVG(500, 500, rawSvgData)
local rect = dgsSVGCreateNode(svgDoc,"rect",50,50,50,50) -- Create SVG node with rect type.
    -- Applying SVG to dgsCreateImage
dgsSVGNodeSetAttributes(rect,{ -- Change the node attributes value .
    dgsCreateImage(0,0,500,500,svg,false)
["stroke"] = {255,255,0},
["stroke-width"] = "5px",
["fill"] = "rgb(255,0,0)",
})


end
local theImage = dgsCreateImage(200,200,500,500,svg,false) --Render the SVG by dgsCreateImage
addEventHandler("onClientResourceStart", resourceRoot, init)
</syntaxhighlight></section>
</syntaxhighlight></section>
==Requirements==
{{Requirements|n/a|1.5.8-9.20979|}}
==See Also==
{{DGS Plugin/SVG}}
===<span style="color:#eb3f00;text-shadow:0.05em 0.05em 0.2em #00000099;">General Functions</span>===
{{DGS General Functions}}

Latest revision as of 13:02, 28 November 2023

Creates an svg from size (blank document), filepath or raw data , similar to svgCreate.

Syntax

svg dgsCreateSVG ( int width, int height [, string pathORrawData ] )

Required Arguments

  • width: Desired width, preferably power of two (16, 32, 64 etc.), maximum is 4096
  • height : Desired height, preferably power of two (16, 32, 64 etc.), maximum is 4096

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • pathOrRawData: A string representing the path to your SVG file, or the raw SVG data

Returns

  • Returns an svg if created successfully, false otherwise.

Example

Click to collapse [-]
Client
loadstring(exports.dgs:dgsImportFunction())() -- load dgs functions using loadstring.

local svg = dgsCreateSVG(500,500) -- Create the SVG . 
local svgDoc = dgsSVGGetDocument(svg) -- Get the SVG Document so you can modify it .
local rect = dgsSVGCreateNode(svgDoc,"rect",50,50,50,50) -- Create SVG node with rect type. 
dgsSVGNodeSetAttributes(rect,{ -- Change the node attributes value .
 	["stroke"] = {255,255,0},
	["stroke-width"] = "5px",
 	["fill"] = "rgb(255,0,0)",
})

local theImage = dgsCreateImage(200,200,500,500,svg,false) --Render the SVG by dgsCreateImage

Requirements

Minimum server version n/a
Minimum client version 1.5.8-9.20979

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.8-9.20979" />

See Also

General Functions