How to check image format in Elixir

So, suppose I have a file that is stored somewhere, and it can either be a file jpeg, or pnghow can I check what it is?

Should I just check the extension? Or should I read the binary signature of the file? Or how to do it?

+4
source share
2 answers

Update: 4/2/2016 to enable .JPG validation .

There's a pretty popular hex Arc package that might work for you. Extracted from the arc:

def validate({file, _}) do
  ~w(.jpg .jpeg .gif .png .JPG) |> Enum.member?(Path.extname(file.file_name))
end
+7
source

, Magic . ,

+1

Source: https://habr.com/ru/post/1614996/


All Articles