Skip to content

Commit

Permalink
feat: more templates, more efficient medialist querying
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Antonenko committed Jul 28, 2023
1 parent eeecdb4 commit a767e09
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 10 deletions.
60 changes: 57 additions & 3 deletions lib/deutexrium/meme.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,58 @@ defmodule Deutexrium.Meme do
%{font: "Noto-Sans-Bold", geometry: "407x61+10+457", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "400x61+436+458", color: "black"}
]
},
%{
template: "mike_wazowski.png",
images: [],
text: [
%{font: "Noto-Sans-Bold", geometry: "884x139+99+56", color: "black"}
]
},
%{
template: "starter_pack.png",
images: [
"209x206!+34+104",
"256x189!+383+242",
"148x154!+276+94",
"212x196!+1+397",
"145x126!+271+441",
],
text: [
%{font: "Noto-Sans-Bold", geometry: "263x76+10+4", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "206x53+36+319", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "112x95+273+254", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "220x59+415+424", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "205x33+1+592", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "174x54+255+569", color: "black"}
]
},
%{
template: "choose_your_class.png",
images: [
"180x140!+27+98",
"180x140!+260+95",
"180x140!+481+95",
"180x140!+23+312",
"180x140!+254+312",
"180x140!+476+312"
],
text: [
%{font: "Noto-Sans-Bold", geometry: "185x35+25+243", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "185x35+256+243", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "185x35+479+244", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "185x35+22+457", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "185x35+250+457", color: "black"},
%{font: "Noto-Sans-Bold", geometry: "185x35+474+457", color: "black"}
]
},
%{
template: "text_msg.png",
images: [],
text: [
%{font: "Noto-Sans-Bold", geometry: "411x71+326+297", color: "white"},
%{font: "Noto-Sans-Bold", geometry: "420x127+101+479", color: "black"}
]
}
]

Expand All @@ -60,11 +112,13 @@ defmodule Deutexrium.Meme do
File.cp(template_path, meme_path)

# overlay images
uri_list = Channel.get_files(channel, ~r/jpg|jpeg|png|webp/)
for geometry <- template_spec.images do
# get image to overlay
url = Channel.get_file(channel, ~r/jpg|jpeg|png|webp/)
# select random image
n = :rand.uniform(length(uri_list)) - 1
uri = uri_list |> Enum.at(n)
dl_target = Path.join(root, "overlay")
{_, 0} = System.cmd("wget", ["-O", dl_target, "--", url],
{_, 0} = System.cmd("wget", ["-O", dl_target, "--", uri],
env: [{"DEUTEX_TOKEN", ""}], stderr_to_stdout: true) # i'm sure wget isn't malicious but..

# overlay image
Expand Down
9 changes: 3 additions & 6 deletions lib/deutexrium/server/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ defmodule Deutexrium.Server.Channel do
@spec get(server_id(), atom()) :: any()
def get(id, setting) when is_tuple(id) and is_atom(setting), do: id |> RqRouter.route_to_chan({:get, setting})

@spec get_file(server_id(), Regex.t) :: String.t
def get_file({id, _}, path_pattern \\ ~r/.*/) do
uri_list = File.read!(Persistence.root_for(id) |> Path.join("media.list"))
@spec get_files(server_id(), Regex.t) :: String.t
def get_files({id, _}, path_pattern \\ ~r/.*/) do
File.read!(Persistence.root_for(id) |> Path.join("media.list"))
|> String.split("\n")
|> Enum.filter(fn x ->
uri = URI.new(x)
Expand All @@ -358,8 +358,5 @@ defmodule Deutexrium.Server.Channel do
_ -> false
end
end)

n = :rand.uniform(length(uri_list)) - 1
uri_list |> Enum.at(n)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Deutexrium.MixProject do
def project do
[
app: :deutexrium,
version: "2.4.3",
version: "2.5.0",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
Binary file added priv/meme_templates/choose_your_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/meme_templates/mike_wazowski.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/meme_templates/starter_pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/meme_templates/text_msg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a767e09

Please sign in to comment.