I am using the Arc library for uploading images to my website, and right now I can upload the original image just fine, but when I use an imagemagick transform to try to get a thumbnail from an image, I get an “is invalid” error.
Here is what the form looks like for uploading an image
use Arc.Definition
# Include ecto support (requires package arc_ecto installed):
use Arc.Ecto.Definition
def __storage, do: Arc.Storage.Local
@versions [:original, :thumb]
# To add a thumbnail version:
# @versions [:original, :thumb]
# Whitelist file extensions:
def validate({file, _}) do
~w(.jpg .jpeg .gif .png) |> Enum.member?(Path.extname(file.file_name))
end
# Define a thumbnail transformation:
def transform(:thumb, _) do
{:convert, "-strip -thumbnail 100x100^ -gravity center -extent 100x100"}
end
If I comment out the transform the image uploads fine. Do I need imagemagick installed on my computer in order to do a transform? I installed it but no luck. There is no documentation saying it needs to be installed either, so is it built into the library or as a dependency of the library?
Could you maybe put an IO.inspect into this function?
def validate({file, _}) do
IO.inspect(file, label: "validate")
~w(.jpg .jpeg .gif .png) |> Enum.member?(Path.extname(file.file_name))
end
Since the changeset error is just “is invalid”, this validate/1 might be returning false (instead of true, then there would be no error).
In case you are not quite yet familiar with elixir’s “ecosystem”, the changeset I keep referring to is Ecto.Changeset — Ecto v3.11.1. arc_ecto uses it to tie up your web form with your database via your app logic in your second code snippet.
When I leave the validate there and only comment out the transform and remove the :thumb version it works just fine, so I don’t think it’s the validate.
Hm, it does have the right extension (".jpg"), so the validate/1 should return true … I expected there to be two calls to this function, with one of them being with an “invalid” extension (from transform/1).
I have changed it to just :original and it works fine like that, but the problem is there is no documentation saying I need imagemagick installed or how it needs to be setup or anything. I used the installer from the website but it hasn’t fixed anything. How can I begin to debug it as an imagemagick problem?
I just ran magick convert 1509807073408.jpg -strip -thumbnail 100x100^ -gravity center -extent 100x100 output.jpg and it worked just fine. So it is in my path and works there.
I am on windows. Convert is a program on windows to convert filesystem types so that is definitely NOT what I want to be running. Will the syntax be different if I am running off of windows rather than :convert?
I actually just tried to change it to {:magick, "convert -strip -thumbnail 100x100^ -gravity center -extent 100x100"} but now I am getting ** (Arc.MissingExecutableError) Cannot locate executable: magick in git-bash but if I run the application from CMD I get same error with is invalid