Added ifunny banner
This commit is contained in:
parent
cde02d1100
commit
13a505c975
BIN
images/banner_ifunny.png
Normal file
BIN
images/banner_ifunny.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
35
memes.lua
35
memes.lua
|
@ -317,11 +317,41 @@ local function add_compression_artifacts_to_image (image_filename, quality)
|
||||||
return output_filename
|
return output_filename
|
||||||
end
|
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 CHANCE_OF_MODIFIER = 0.3
|
||||||
|
|
||||||
local modifiers = {
|
local modifiers = {
|
||||||
-- Compression artifacts
|
-- Compression artifacts
|
||||||
function (image_filename) return add_compression_artifacts_to_image(image_filename, math.random(1, 20)) end,
|
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,
|
||||||
}
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -358,9 +388,10 @@ local function download_and_standardize_image (image_url)
|
||||||
|
|
||||||
-- Convert svg to png
|
-- Convert svg to png
|
||||||
if success and url:match '%.svg$' then
|
if success and url:match '%.svg$' then
|
||||||
local filename_2 = CONFIG.IMGGEN_PATH_OUTPUT..'topic_'..topic.topic..'.'..'png'
|
local filename_2 = filename..'.svg'
|
||||||
os.execute('convert -density "1200" -resize 400x400 "'..filename..'" "'..filename_2..'" &> /dev/null')
|
os.execute('convert -density "1200" -resize 400x400 "'..filename..'" "'..filename_2..'" &> /dev/null')
|
||||||
filename = filename_2
|
filename = filename_2
|
||||||
|
assert(check_file_exists(filename_2))
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
|
||||||
|
@ -448,7 +479,7 @@ local function generate_comparison_meme_generator (positions)
|
||||||
local image_filename = save_img(base_img)
|
local image_filename = save_img(base_img)
|
||||||
|
|
||||||
-- Use modifiers
|
-- Use modifiers
|
||||||
if math.random() < CHANCE_OF_MODIFIER then
|
while math.random() < CHANCE_OF_MODIFIER do
|
||||||
image_filename = choose(modifiers)(image_filename)
|
image_filename = choose(modifiers)(image_filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user