Added conversion from svg to png, and fixed some minor bugs
This commit is contained in:
parent
19a7755306
commit
da8edd57ce
|
@ -77,7 +77,7 @@ local function search_wikipedia_for_images (topics, language, topic_to_image_url
|
||||||
|
|
||||||
-- Determine topic to image
|
-- Determine topic to image
|
||||||
for _, page in pairs(data.query.pages) do
|
for _, page in pairs(data.query.pages) do
|
||||||
local orig_title = redirected_topics[ page.title ]
|
local orig_title = redirected_topics[ page.title ] or page.title
|
||||||
if not topic_to_image_url[orig_title] then
|
if not topic_to_image_url[orig_title] then
|
||||||
local found_url = false
|
local found_url = false
|
||||||
if page.original then found_url = page.original.source end
|
if page.original then found_url = page.original.source end
|
||||||
|
|
15
main.lua
15
main.lua
|
@ -127,6 +127,7 @@ local function fill_in_topics_information (topics)
|
||||||
assert(type(topic) == 'string')
|
assert(type(topic) == 'string')
|
||||||
|
|
||||||
local url = topic_to_image_url[topic]
|
local url = topic_to_image_url[topic]
|
||||||
|
print(topic, url)
|
||||||
|
|
||||||
if url then new_topics[i] = { topic = topic, type = 'image', url = url }
|
if url then new_topics[i] = { topic = topic, type = 'image', url = url }
|
||||||
else new_topics[i] = { topic = topic, type = 'text', text = topic }
|
else new_topics[i] = { topic = topic, type = 'text', text = topic }
|
||||||
|
@ -141,9 +142,19 @@ local function paste_topic_onto_image (target, topic, x, y, w, h, bg_color, font
|
||||||
assert(type(font_name) == 'string')
|
assert(type(font_name) == 'string')
|
||||||
-- Download and paste found image
|
-- Download and paste found image
|
||||||
if topic.type == 'image' then
|
if topic.type == 'image' then
|
||||||
local url, filename = topic.url, CONFIG.IMGGEN_PATH_OUTPUT..'topic_'..topic.topic..'.png'
|
local file_extension = topic.url:match '%.(%a+)$'
|
||||||
|
local url, filename = topic.url, CONFIG.IMGGEN_PATH_OUTPUT..'topic_'..topic.topic..'.'..file_extension
|
||||||
|
assert(type(url) == 'string' and #url > 0)
|
||||||
|
assert(type(filename) == 'string' and #filename > 0)
|
||||||
internet.download_file(url, filename)
|
internet.download_file(url, filename)
|
||||||
local found_img = imlib.image.load(filename)
|
-- Convert svg to png
|
||||||
|
if url:match '%.svg$' then
|
||||||
|
local filename_2 = CONFIG.IMGGEN_PATH_OUTPUT..'topic_'..topic.topic..'.'..'png'
|
||||||
|
os.execute('convert -density 1200 -resize 400x400 '..filename..' '..filename_2)
|
||||||
|
filename = filename_2
|
||||||
|
end
|
||||||
|
--
|
||||||
|
local found_img = assert(imlib.image.load(filename))
|
||||||
found_img:crop_and_scale(0, 0, found_img:get_width(), found_img:get_height(), w, h)
|
found_img:crop_and_scale(0, 0, found_img:get_width(), found_img:get_height(), w, h)
|
||||||
flatten_onto (target, found_img, x, y)
|
flatten_onto (target, found_img, x, y)
|
||||||
found_img:free()
|
found_img:free()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user