Skip to content

Instantly share code, notes, and snippets.

@trojanh
Last active March 16, 2022 07:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trojanh/319d8c01b3c4c139bd1df930ea1c5d48 to your computer and use it in GitHub Desktop.
Save trojanh/319d8c01b3c4c139bd1df930ea1c5d48 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