Fix for missing font colors, resulting in bad memes.
This commit is contained in:
parent
575c481ad4
commit
cde02d1100
13
memes.lua
13
memes.lua
|
@ -169,6 +169,8 @@ local COLOR_BLACK = imlib.color.new( 0, 0, 0)
|
|||
|
||||
local function draw_centered_lines (draw_onto, lines, x0, y0, width, font, font_colors)
|
||||
assert(type(lines) == 'table')
|
||||
assert(type(font_colors) == 'table' and #font_colors >= 1)
|
||||
--
|
||||
local y = y0
|
||||
for i, line in ipairs(lines) do
|
||||
local text_w, text_h = font:get_size(line)
|
||||
|
@ -213,16 +215,20 @@ local function determine_font_and_lines_for_box (font_name, text, width, height)
|
|||
local actual_font = load_font_of_size(font_name, min_font_size)
|
||||
|
||||
-- Assertions and error correction
|
||||
--[[
|
||||
if (#actual_lines * select(2, actual_font:get_size(text)) < height) then
|
||||
io.write(' !! Performed bad fitting of text: '..text..'\n')
|
||||
actual_font, actual_lines = determine_required_font_size(font_name, text, width), {text}
|
||||
end
|
||||
--]]
|
||||
|
||||
return actual_font, actual_lines
|
||||
end
|
||||
|
||||
local function draw_centered_text_in_box (font_name, draw_onto, text, x0, y0, width, height, bg_color, font_colors)
|
||||
assert(type(font_name) == 'string')
|
||||
assert(type(font_colors) == 'table' and #font_colors >= 1)
|
||||
--
|
||||
local font, lines = determine_font_and_lines_for_box(font_name, text, width, height)
|
||||
--
|
||||
local y = y0 + (height - #lines * select(2, font:get_size(text))) / 2
|
||||
|
@ -248,6 +254,10 @@ local function paste_topic_onto_image (target, topic, x, y, w, h, bg_color, font
|
|||
assert(target)
|
||||
assert(type(topic) == 'table')
|
||||
assert(type(font_name) == 'string')
|
||||
|
||||
if not font_color then font_color = { COLOR_BLACK } end
|
||||
assert(type(font_color) == 'table' and #font_color >= 1)
|
||||
|
||||
-- Download and paste found image
|
||||
if topic.type == 'image' then
|
||||
assert(type(topic.filename) == 'string')
|
||||
|
@ -417,6 +427,8 @@ local function generate_comparison_meme_generator (positions)
|
|||
-- Paste topic onto head
|
||||
for index, pos in ipairs(rand_positions) do
|
||||
-- Font colors
|
||||
if pos.font_color == nil then pos.font_color = COLOR_BLACK end
|
||||
|
||||
local font_colors = {}
|
||||
if pos.font_color == COLOR_WHITE then font_colors[1] = COLOR_BLACK
|
||||
elseif pos.font_color == COLOR_BLACK then font_colors[1] = COLOR_WHITE
|
||||
|
@ -425,6 +437,7 @@ local function generate_comparison_meme_generator (positions)
|
|||
|
||||
-- Paste
|
||||
assert(base_img, topics[index])
|
||||
assert(type(font_colors) == 'table' and #font_colors >= 1)
|
||||
paste_topic_onto_image(base_img, topics[index], pos.x, pos.y, pos.w, pos.h, nil, font_name, font_colors)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user