Page 1 of 1

how to use -write mpr:

Posted: 2020-05-04T05:30:01-07:00
by CanadianHusky

On Windows the following command gives an error.

Code: Select all

>magick "C:\input.jpg" -clahe 150x150+32+4% -colorspace gray -write mpr:step1 -blur 3x15 -black-threshold 35% +dither -colors 2 -normalize -write "C:\mask_1.jpg" +delete mpr:step1 +append -black-threshold 35% +dither -colors 2 -normalize -write "C:\mask_2.jpg"
magick: MissingArgument `-write' at CLI arg 27 @ fatal/magick-cli.c/ProcessCommandOptions/447.

I am trying to write part of the processing to memory, with -write mpr:step1 and reuse it later. The command is expected to create 2 files. The state at mpr:step1 is expected to be reloaded and reused where the +append command is. I read the explanation from but it seems I didnt understand it fully.

What am I doing wrong ? Can someone help please.
thank you

Re: how to use -write mpr:

Posted: 2020-05-04T06:11:09-07:00
by snibgo
Read the error message. It is complaining about the 27th argument. Count them in your command. This is the final "-write", to a file.

The problem is that IM expects the final option to be simply a file name. For that name, "-write" is implied. It is an error to include "-write".

So the cure is either to remove "-write", or add another filename at the end, and that could be "null:".

Re: how to use -write mpr:

Posted: 2020-05-04T23:58:30-07:00
by CanadianHusky
Understood. Thank you.
The -write argument is present because the actual script is much longer and executed from a text file.
Without the -write at the end, the script fails with an error, which itself took a while to figure out that -write MUST be present when executing from script.
It was my incorrect assumption that -write would work from the command line as well.
I understand the behaviour now (although a bit confusing) and corrected the problem with your tip, thank you.

Re: how to use -write mpr:

Posted: 2020-05-05T04:45:52-07:00
by snibgo
My response above was accurate for running IM from the command line or for shell scripts (bash, Windows BAT, etc).

If you use IM scripts (eg "magick -script myscript.txt") the situation is different, and you need explicit "-write" keywords. For that, you need "-write" before the final output file. You could also use "-exit" at the end, after writing the file.

@fmw42: "-exit" and "-script" are not documented in ... ptions.php . Can these be added, please?

Re: how to use -write mpr:

Posted: 2020-05-05T10:01:54-07:00
by CanadianHusky
It is exactly that link that you mentioned, ... ptions.php where I searched up and down to understand how the pure command command line and how -script and -write works, looking for examples.

I did find it a bit inconsistent that -write at the command line MUST NOT exist, or causes error, when it MUST exist at the -script mode
It would be nice to update the documentation, thank you again

Re: how to use -write mpr:

Posted: 2020-05-05T10:37:00-07:00
by snibgo
CanadianHusky wrote:I did find it a bit inconsistent that ...
Yes. The reason is that IM has evolved over the decades. It started with the traditional Unix syntax of:

Code: Select all

{program-name} {options} {input-file} {output-file}
... but evolved into accepting multiple inputs, and capable of writing multiple outputs, with some options applying to only some inputs, and so on.

The current situation is that a command ending in a filename has an implied "-write", but a filename elsewhere has an implied "-read". Magick scripts have no implied "-write". In my view, IM commands would be easier for beginners if these keywords were always required, and never implied. But that would break all existing shell scripts.