From c501c4e6a419c2b0020101ccc9d8a449390ea671 Mon Sep 17 00:00:00 2001 From: Chidambaram Nachiappan <60850111+thechidambaram@users.noreply.github.com> Date: Wed, 23 Feb 2022 21:42:19 +0000 Subject: Generate svg preview instead of png --- make_preview_image.lua | 32 +++++++++++--------------------- 1 file 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(' \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 = ' \n' + fp:write(rect) end -fp:close() +fp:write('') +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)) -- cgit v1.2.3