|
Overview Lua-GD is a set of Lua bindings to the Thomas Boutell's gd library that allows your code to quickly draw complete images with lines, polygons, arcs, text, multiple colors, cut and paste from other images, flood fills, read in or write out images in the PNG, JPEG or GIF format. It is not a kitchen-sink graphics package, but it does include most frequently requested features, including both truecolor and palette images, resampling (smooth resizing of truecolor images) and so forth. It is particularly useful in Web applications. Lua-GD is copyrighted free software, distributed under the MIT license (the same used by Lua 5.1) and it can be used at no cost for both academic and commercial purpouses. You need also to agree with to the gd license. If you use this package in a product, an acknowledgment in the product documentation would be greatly appreciated (but it is not required).
Installation Here is how to make the Lua-GD Lua module available to your AutoPlay Media Studio 8.0 project. 1. Download the Lua module and extract it to a temporary location. 2. Copy all files from the extracted folder (excluding the "demos" and "doc" folders) to your project's Scripts folder. 3. Add the following require to your project, e.g. in Global Functions or where they will be used: require "gd"
Usage The functions are documented in the manual located in the "doc" folder of the download, and online here: http://lua-gd.luaforge.net/manual.html
Example:
-- This example draws the famous Sierpinski triangle with lua-gd
-- and outputs it to an image in "C:temp_outputsierpinski.png"
-- Note: The folder "temp_output" must already exist.
-- This example was taken from the Lua-GD documentation.
require "gd"
size = 250
im = gd.createPalette(size, size)
white = im:colorAllocate(255, 255, 255)
black = im:colorAllocate(0, 0, 0)
m = {}
m[math.floor(size/2)] = true
for i = 1, size do
n = {}
for j = 1, size do
if m[j] then
im:setPixel(j, i, black)
n[j+1] = not n[j+1]
n[j-1] = not n[j-1]
end
end
m = n
end
im:png("C:\temp_output\sierpinski.png");
Credits Author: Alexandre Erwin Ittner
E-mail: aittner#netuno.com.br (e-mail obfuscated to avoid spam-bots. Please replace the "#" with an "@"). GnuPG/PGP Key: 0x0041A1FB (key fingerprint: 9B49 FCE2 E6B9 D1AD 6101 29AD 4F6D F114 0041 A1FB). Homepage: http://users.netuno.com.br/aittner/. Location: Jaragu? do Sul, Santa Catarina, Brazil.

|