diff --git a/lib/philomena/intensities.ex b/lib/philomena/intensities.ex new file mode 100644 index 00000000..a20697a5 --- /dev/null +++ b/lib/philomena/intensities.ex @@ -0,0 +1,23 @@ +defmodule Philomena.Intensities do + @doc """ + Gets the corner intensities of the given image file. + The image file must be in the PNG or JPEG format. + """ + @spec file(String.t()) :: {:ok, map()} | :error + def file(input) do + System.cmd("image-intensities", [input]) + |> case do + {output, 0} -> + [nw, ne, sw, se] = + output + |> String.trim() + |> String.split("\t") + |> Enum.map(&String.to_float/1) + + {:ok, %{nw: nw, ne: ne, sw: sw, se: se}} + + _error -> + :error + end + end +end \ No newline at end of file diff --git a/lib/philomena/mime.ex b/lib/philomena/mime.ex new file mode 100644 index 00000000..d22a8705 --- /dev/null +++ b/lib/philomena/mime.ex @@ -0,0 +1,16 @@ +defmodule Philomena.Mime do + @doc """ + Gets the MIME type of the given pathname. + """ + @spec file(String.t()) :: {:ok, binary()} | :error + def file(path) do + System.cmd("file", ["-b", "--mime-type", path]) + |> case do + {output, 0} -> + {:ok, String.trim(output)} + + _error -> + :error + end + end +end \ No newline at end of file diff --git a/vagrant/install.bash b/vagrant/install.bash index 237191a2..377207db 100644 --- a/vagrant/install.bash +++ b/vagrant/install.bash @@ -54,11 +54,21 @@ apt-get update if ! install_packages build-essential postgresql-11 libpq-dev nginx nodejs \ elasticsearch esl-erlang elixir inotify-tools git \ redis-server automake libtool zlib1g-dev ffmpeg \ - libavutil-dev libavcodec-dev libavformat-dev ; then + libavutil-dev libavcodec-dev libavformat-dev \ + libmagic-dev libpng-dev; then >&2 echo "Installation of dependencies failed." exit 1 fi +if [ ! -f /usr/local/bin/image-intensities ]; then + pushd . + cd /tmp + git clone https://github.com/derpibooru/cli_intensities + cd cli_intensities + make install + popd +fi + sed -i -e 's/\(-Xm[sx]\)1g/\1256m/' /etc/elasticsearch/jvm.options systemctl enable elasticsearch 2>/dev/null service elasticsearch start