Skip to content

Instantly share code, notes, and snippets.

@keslert
Created January 23, 2016 23:13
Show Gist options
  • Save keslert/445671bf256622319f84 to your computer and use it in GitHub Desktop.
Save keslert/445671bf256622319f84 to your computer and use it in GitHub Desktop.
defmodule Project.BookImage do
use Arc.Definition
use Arc.Ecto.Definition
# To add a thumbnail version:
@versions [:original, :small, :thumb]
@extension_whitelist ~w(.jpg .jpeg .gif .png)
def validate({file, _}) do
file_extension = file.file_name |> Path.extname |> String.downcase
Enum.member?(@extension_whitelist, file_extension)
end
def transform(:small, _) do
{:convert, "-strip -thumbnail 200x200 -format jpg"}
end
def transform(:thumb, _) do
{:convert, "-strip -thumbnail 75x75 -format jpg"}
end
# Override the persisted filenames:
def filename(version, _) do
version
end
# Override the storage directory:
def storage_dir(version, {_, scope}) do
"uploads/books/#{scope.uuid}/"
end
# Provide a default URL if there hasn't been a file uploaded
def default_url(:small, _) do
"http://placehold.it/200x200"
end
def default_url(:thumb, _) do
"http://placehold.it/75x75"
end
def default_url(_version, _) do
"http://placehold.it/200x250"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment