Added ifunny banner

This commit is contained in:
Jon Michael Aanes 2018-06-27 13:17:50 +02:00
parent cde02d1100
commit 13a505c975
2 changed files with 45 additions and 14 deletions

BIN
images/banner_ifunny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -317,11 +317,41 @@ local function add_compression_artifacts_to_image (image_filename, quality)
return output_filename
end
local function add_banner_to_image (image_filename, banner_filename, x_offset, background_color)
assert(type(image_filename) == 'string')
assert(type(banner_filename) == 'string')
assert(type(x_offset) == 'number')
--
local image_img = assert(imlib.image.load(image_filename))
local banner_img = assert(imlib.image.load(banner_filename))
local combi_img = imlib.image.new( image_img:get_width(), image_img:get_height() + banner_img:get_height() )
local xpos = (0 <= x_offset) and x_offset or (combi_img:get_width() - banner_img:get_width() + x_offset)
-- Draw
if background_color then
combi_img:draw_rectangle(0, 0, combi_img:get_width(), combi_img:get_height(), background_color)
end
flatten_onto(combi_img, image_img, 0, 0)
flatten_onto(combi_img, banner_img, xpos, image_img:get_height())
-- Save and free
image_img:free()
banner_img:free()
local output_filename = os.tmpname()..'.jpg'
combi_img:save(output_filename)
combi_img:free()
return output_filename
end
local CHANCE_OF_MODIFIER = 0.3
local modifiers = {
-- Compression artifacts
function (image_filename) return add_compression_artifacts_to_image(image_filename, math.random(1, 20)) end,
-- iFunny banner
function (image_filename) return add_banner_to_image(image_filename, 'images/banner_ifunny.png', -7, imlib.color.new(27, 27, 27)) end,
}
--------------------------------------------------------------------------------
@ -350,21 +380,22 @@ local DROSTE_EFFECT_TRIGGERS = {
}
local function download_and_standardize_image (image_url)
local file_extension = image_url:match '%.(%a+)$'
local url, filename = image_url, os.tmpname()
assert(type(url) == 'string' and #url > 0)
assert(type(filename) == 'string' and #filename > 0)
local success, errmsg = internet.download_file(url, filename)
local file_extension = image_url:match '%.(%a+)$'
local url, filename = image_url, os.tmpname()
assert(type(url) == 'string' and #url > 0)
assert(type(filename) == 'string' and #filename > 0)
local success, errmsg = internet.download_file(url, filename)
-- Convert svg to png
if success and 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..'" &> /dev/null')
filename = filename_2
end
--
-- Convert svg to png
if success and url:match '%.svg$' then
local filename_2 = filename..'.svg'
os.execute('convert -density "1200" -resize 400x400 "'..filename..'" "'..filename_2..'" &> /dev/null')
filename = filename_2
assert(check_file_exists(filename_2))
end
--
return success and filename, errmsg
return success and filename, errmsg
end
local function fill_in_topics_information (topics)
@ -448,7 +479,7 @@ local function generate_comparison_meme_generator (positions)
local image_filename = save_img(base_img)
-- Use modifiers
if math.random() < CHANCE_OF_MODIFIER then
while math.random() < CHANCE_OF_MODIFIER do
image_filename = choose(modifiers)(image_filename)
end