diff --git a/internet.lua b/internet.lua index a484d76..4b530aa 100644 --- a/internet.lua +++ b/internet.lua @@ -77,7 +77,7 @@ local function search_wikipedia_for_images (topics, language, topic_to_image_url -- Determine topic to image 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 local found_url = false if page.original then found_url = page.original.source end diff --git a/main.lua b/main.lua index 03b457f..0a202de 100644 --- a/main.lua +++ b/main.lua @@ -127,6 +127,7 @@ local function fill_in_topics_information (topics) assert(type(topic) == 'string') local url = topic_to_image_url[topic] + print(topic, url) if url then new_topics[i] = { topic = topic, type = 'image', url = url } else new_topics[i] = { topic = topic, type = 'text', text = topic } @@ -141,10 +142,20 @@ local function paste_topic_onto_image (target, topic, x, y, w, h, bg_color, font assert(type(font_name) == 'string') -- Download and paste found image 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) - local found_img = imlib.image.load(filename) - found_img:crop_and_scale(0, 0, found_img:get_width(), found_img:get_height(), w, h) + -- 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) flatten_onto (target, found_img, x, y) found_img:free() --os.remove(filename)