kokolegorille

kokolegorille

Hello everyone,

I am trying to run image magick convert from Elixir. The command I am trying to replicate is…

$ convert -size 200x200 xc:Black -fill White -draw 'circle 100 100 100 1' -alpha Copy mask.png

Which is working fine in the shell. It generates a new image correctly.

And now I am trying to do this in the BEAM.

  def build_mask(size) do
    params = [
      "-size",
      "#{size}x#{size}",
      "xc:Black",
      "-fill",
      "White",
      "-draw",
      "'circle 100 100 100 1'",
      "-alpha",
      "Copy",
      "mask.png"
    ]
    System.cmd(convert(), params)
  end

  defp convert() do
    case System.cmd("which", ["convert"]) do
      {convert_cmd, 0} -> String.trim_trailing(convert_cmd, "\n")
      {_, 1} -> ""
    end
  end

which fails with

convert: non-conforming drawing primitive definition `circle 100 100 100 1' @ error/draw.c/RenderMVGContent/4397.

The problem is in these lines, if I comment them, the command is working.

"-draw",
"'circle 100 100 100 1'",

So my question is how to pass a quoted parameters like this ‘circle 100 100 100 1’.

I have been trying different combination, with escape, double quote and what not.

Does anybody hit the same problem trying to wrap convert command in the BEAM?

Thanks for taking time

Showing Posts 1 to 7

NobbZ

NobbZ

The quotes are a shell thing, just leave them off and just use "circle 100 100 100 1".

kokolegorille

kokolegorille OP

Oh my… it is now working fine :slight_smile:

sergio

sergio

I’m running into a similar issue trying to run wkhtmltopdf with a string HTML.

    html_string =
      Phoenix.View.render_to_string(FooWeb.PdfView, "contract.html",
        test_name: "Brawl Smash Bros."
      )

    download_folder = Application.app_dir(:myapp, ["priv", "static", "pdfs"])
    pdf_save_path = "#{download_folder}/contract.pdf"

    IO.inspect("wkhtmltopdf " <> html_string <> " " <> pdf_save_path)

    System.cmd("wkhtmltopdf", [html_string, pdf_save_path])

Result:

iex [16] > myapp.Pdf.generate_team_contract()
"wkhtmltopdf <h1>This is your team contract</h1>\n\n<p>You are playing in Brawl Smash Bros.</p> /home/sergio/Work/myapp/_build/dev/lib/myapp/priv/static/pdfs/team-contract.pdf"
Loading pages (1/6)
Error: Failed to load http:/p>, with network status code 3 and http status code 0 - Host  not found
                                                                                                   Error: Failed loading page http:/h1>

                  <p>You are playing in Brawl Smash Bros.</p> (sometimes it will work just to ignore this error with --load-error-handling ignore)
                             Exit with code 1 due to network error: HostNotFoundError
                                                                                     {"", 1}

Anyone have any tips on how to run this command? The HTML isn’t being quoted.

al2o3cr

al2o3cr

I don’t see any mention of passing HTML directly via the command line in the wkhtmltopdf docs, escaped or otherwise.

03juan

03juan

wkhtmltopdf expects a URL or file. You’ll have to File.write(tmp_html_path, html_string) and System.cmd("wkhtmltopdf", [tmp_html_path, pdf_save_path])

sergio

sergio

Maybe I misread? I thought you could pass in a string.

03juan

03juan

That answer is about piping the output of echo in bash, I don’t think you can do that within Elixir.

I was going by the help file linked above by @al2o3cr

A page objects puts the content of a single webpage into the output document.
(page)? <input url/file name> [PAGE OPTION]…

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews