Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional versions/transforms #147

Open
MartinElvar opened this issue Jan 12, 2017 · 2 comments
Open

Conditional versions/transforms #147

MartinElvar opened this issue Jan 12, 2017 · 2 comments

Comments

@MartinElvar
Copy link
Contributor

Basically i have a generic uploader, which handles uploads of images, videos, and audio files.

I case that the file type is not a image, i don't want to create a thumbnails, as thumbnails of a audio file don't really makes sense.

I currently just reply with :noreply if that is the case, but this will make 3 copys of the same file. Is it somehow possible to disregard transform if a condition is not met?

This is my current code, making 3x videos/audio files.

  # Define a thumbnail transformation:
  def transform(:thumb, {file, _}) do
    if Enum.member?(~w(.jpg .jpeg .gif .png), Path.extname(file.file_name)) do
      {:convert, "-strip -thumbnail 150x150 -gravity center -format png", :png}
    else
      :noaction
    end
  end

  # Define a thumbnail transformation:
  def transform(:thumb_small, {file, _}) do
    if Enum.member?(~w(.jpg .jpeg .gif .png), Path.extname(file.file_name)) do
      {:convert, "-strip -thumbnail 20x20 -gravity center -format png", :png}
    else
      :noaction
    end
  end
@taorg
Copy link

taorg commented Feb 15, 2017

It doesn't work because you assume you already have the file, but you don't.
transform function is invoked before the file is in the upload folder
Try this and you would understand:

def transform(:original, _) do
  {:convert, fn(input, output) ->
     IO.inspect input
     IO.inspect output
  "#{input}  #{output}" end, :jpg}
 end

@taorg
Copy link

taorg commented Feb 15, 2017

Although it doesn't mean you can't
Try this:
def transform(:original, toLog) do IO.inspect toLog {:convert, fn(input, output) -> "#{input} #{output}" end, :jpg} end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants