Last active
March 16, 2022 07:35
-
-
Save trojanh/319d8c01b3c4c139bd1df930ea1c5d48 to your computer and use it in GitHub Desktop.
Create Image thumbnail using ImageMagick in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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