Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "gd"
- function gdplot(file, itype)
- --Get image type
- itype = string.sub(file, -4, -1)
- itype = string.gsub(itype, '%.', '')
- --Open image
- if itype == 'jpeg' or itype == 'jpg' then
- im = gd.createFromJpeg(file)
- elseif itype == 'png' then
- im = gd.createFromPng(file)
- elseif itype == 'gif' then
- im = gd.createFromGif(file)
- end
- --Height, width
- local w, h = im:sizeXY()
- --is it bigger than the screen?
- if w >= 610 then
- w = 610
- end
- if h > 380 then
- h = 380
- end
- --Run through the image
- for x = 0, w do
- for y = 0, h do
- --Get color as hex string...
- color = tostring(bit.tohex(im:getPixel(x, y)))
- --and take the r, g, b individual values.
- r = string.sub(color, 3, 4)
- g = string.sub(color, 5, 6)
- b = string.sub(color, 7, 8)
- --Draw a pixel
- tpt.create(x, y, "dmnd")
- tpt.set_property("dcolor", '0xFF' .. r .. g .. b, x, y)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment