From 3e078c689789cea2e9798899f4e2f5f5a0b9b5a0 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 17 Sep 2023 14:09:40 -0400 Subject: Added manifest.json. --- scripts/make_preview_image.lua | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 scripts/make_preview_image.lua (limited to 'scripts/make_preview_image.lua') diff --git a/scripts/make_preview_image.lua b/scripts/make_preview_image.lua new file mode 100755 index 0000000..6bcaac8 --- /dev/null +++ b/scripts/make_preview_image.lua @@ -0,0 +1,51 @@ +#!/usr/bin/lua + +local filename = ... +local name = filename:match("([^\\/]+)%..*$") + + +-- get colors +local text = io.open(filename):read("*a") +local colors = {} +for r, g, b in text:gmatch("#(%x%x)(%x%x)(%x%x)") do + r = tonumber(r, 16) + g = tonumber(g, 16) + b = tonumber(b, 16) + table.insert(colors, { r, g, b }) +end + +table.sort(colors, function(a, b) + return a[1] + a[2] + a[3] < b[1] + b[2] + b[3] +end) + +local function eq(a, b) + return a[1] == b[1] and a[2] == b[2] and a[3] == b[3] +end + +local prev = {} +for i = #colors, 1, -1 do + if eq(colors[i], prev) then + table.remove(colors, i) + else + prev = colors[i] + end +end + + +--generate svg file +local w = 200 +local h = 16 +local fp = io.open("previews/" .. name .. ".svg", "wb") + +fp:write(' \n') + +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:write('') +fp:close() + -- cgit v1.2.3