1

I want to use the imagemagick convert command to draw on a image file. I have the image data as raw-text in a buffer and now I would like to run convert - -draw 'rectangle 0,0,100,100' - on it (the dashes tell convert to use stdin for input and print the data to stdout). If I leave out the -draw 'rectangle 0,0,100,100' then I can just use (call-process-region (point-min) (point-max) "convert" t t nil "-" "-") to pass the buffer contents as stdin to the convert program and insert the from convert returned image data in the buffer (this does not do anything but it works, e.g. I could replace the last - with a filename to write the resulting image data to a file). However now I want to add the -draw 'rectangle 0,0,100,100' as an extra argument to call-process-region but I really can not find (out) how to do this properly. For example I tried (call-process-region (point-min) (point-max) "convert" t t nil "-" "-draw" "'rectangle 0,0,50,50'" "-") but then I get message convert: non-conforming drawing primitive definition rectangle 0,0,50,50' @ error/draw.c/RenderMVGContent/4473.`

I tried to run it as a shell-command (i.e. using /bin/bash -c)? But then I don't know how to pass the buffer contents as input.

So I would like to know how to properly pass the single-quotes string 'rectangle 0,0,100,100' to the command.

(FYI I would like to extend djvu.el to show annotations)

1 Answer 1

2

I would like to run convert - -draw 'rectangle 0,0,100,100' -

Note that you're quoting for the shell there, so that it will not break that argument into two, on account of the space.

For example I tried (call-process-region (point-min) (point-max) "convert" t t nil "-" "-draw" "'rectangle 0,0,50,50'" "-")

Note that you've included the quotes which are for the shell in a call which is not being processed by a shell, which means that the convert process is receiving an argument containing those ' surrounding characters.

That is like running this shell command:

convert - -draw "'rectangle 0,0,100,100'" -

Try:

(call-process-region (point-min) (point-max) "convert" t t nil
                     "-" "-draw" "rectangle 0,0,50,50" "-")
1
  • Thanks for the quick answer and nice explanation. It took me a long way to get to this point (trying many things before) and because I really spent too much time already I thought I should just ask here. Then, just after I posted this question I found the function call-shell-region which worked for me also. But anyway, your answer helps me to understand why things work how they work, which is very important to me. Great! Commented Sep 15, 2020 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.