Skip to content

Instantly share code, notes, and snippets.

@alexfilatov
Forked from trojanh/Transformer.ex
Created August 6, 2018 21:00
Show Gist options
  • Save alexfilatov/6d3613445d2e8e4acbd768185b237001 to your computer and use it in GitHub Desktop.
Save alexfilatov/6d3613445d2e8e4acbd768185b237001 to your computer and use it in GitHub Desktop.
Create Image thumbnail using ImageMagick in Elixir
defmodule Image.Transformer do
def transform(original_file, operation \\ "convert") do
thumb_path = generate_thumb_file(original_file)
System.cmd(operation, operation_commands(original_file_path, thumb_path))
thumb_path
end
defp generate_thumb_file(original_file) do
original_file
|> String.replace(".", "_thumb.")
end
defp operation_commands(original_file_path, thumb_path, size \\ "250x90") do
[
"-define",
"jpeg:size=500x180",
original_file_path,
"-auto-orient",
"-thumbnail",
size,
"-unsharp",
"0x.5",
thumb_path
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment