Instantly share code, notes, and snippets.

Embed
What would you like to do?
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