diff options
author | Chidambaram Nachiappan <60850111+thechidambaram@users.noreply.github.com> | 2022-02-23 21:42:19 +0000 |
---|---|---|
committer | Chidambaram Nachiappan <60850111+thechidambaram@users.noreply.github.com> | 2022-02-23 21:42:19 +0000 |
commit | c501c4e6a419c2b0020101ccc9d8a449390ea671 (patch) | |
tree | 5799a2e81abeda4b8ecbb624607829e86816ae14 | |
parent | b383fb287b3501dc3b927e5c63a3420d84795857 (diff) | |
download | lite-xl-colors-c501c4e6a419c2b0020101ccc9d8a449390ea671.tar.gz lite-xl-colors-c501c4e6a419c2b0020101ccc9d8a449390ea671.zip |
Generate svg preview instead of png
-rwxr-xr-x | make_preview_image.lua | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/make_preview_image.lua b/make_preview_image.lua index 31f088d..bf0d4ee 100755 --- a/make_preview_image.lua +++ b/make_preview_image.lua @@ -32,30 +32,20 @@ for i = #colors, 1, -1 do end --- generate ppm file +--generate svg file local w = 200 local h = 16 -local fp = io.open(name .. ".ppm", "wb") -fp:write("P3\n") -fp:write(w, " ", h, "\n") -fp:write("255\n") - -local row = {} -for i = 0, w - 1 do - local idx = math.floor((#colors / w) * i) + 1 - local r, g, b = table.unpack(colors[idx]) - table.insert(row, r) - table.insert(row, g) - table.insert(row, b) -end -row = table.concat(row, " ") .. "\n" +local fp = io.open(name .. ".svg", "wb") + +fp:write('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'..w..'" height="'..h..'"> \n') -for i = 1, h do - fp:write(row) +for i = 1, #colors do + local width = w/#colors + local r, g, b = table.unpack(colors[i]) + local rect = '<rect x="'..(i-1)*width..'" width="'..width..'" height="'..h..'" fill="rgb('..r..', '..g..', '..b..')"></rect> \n' + fp:write(rect) end -fp:close() +fp:write('</svg>') +fp:close() --- convert ppm file to png -os.execute(string.format("convert %s.ppm %s.png", name, name)) -os.execute(string.format("rm %s.ppm", name)) |