IM7 -script option usage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
aperly
Posts: 4
Joined: 2015-12-26T14:44:26-07:00
Authentication code: 1151

IM7 -script option usage

Post by aperly »

Hi. I've got an issue with ImageMagick 7.0.0-0 Q16 x64 2015-12-20 (win64-portable).
This works well:

Code: Select all

magick -size 42x42 xc:red t.png

However, when I try:

Code: Select all

echo -size 42x42 xc:red t.png | magick -script -
IM gives me the following errors:
magick: UnableToOpenBlob 't.png': No such file or directory @ error/blob.c/OpenBlob/2692.
magick: UnableToOpenFile `t.png' @ error/png.c/ReadPNGImage/3974.
It looks like everything is considered as an input. I want to specify my output here.

What am I doing wrong? Thank! :)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: IM7 -script option usage

Post by magick »

Try this instead:
  • echo -size 42x42 xc:red -write t.png | magick -script -
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM7 -script option usage

Post by fmw42 »

I do not think you can put input or output files in the script.

I tried this with no errors, but the image was not created.

Code: Select all

echo "-size 42x42 xc:red" | magick -verbose -script - t.png 
Same result putting -size 42x42 xc:red in a file (script.txt) and doing

Code: Select all

 magick -verbose -script script.txt t.png 
No image was created. I was using IM 7 from Dec 26, 2015.
aperly
Posts: 4
Joined: 2015-12-26T14:44:26-07:00
Authentication code: 1151

Re: IM7 -script option usage

Post by aperly »

magick wrote:Try this instead:
  • echo -size 42x42 xc:red -write t.png | magick -script -
Perfect! Thanks again.

Now I can write very long commands easily.

PS: Was is documented somewhere? I cannot find any reference to it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM7 -script option usage

Post by fmw42 »

Did you get an output. I did not on Mac OSX with my commands above (without the -write)?

There is a short document, but right now I cannot find it either.

I would suggest you put the echo text into quotes also.

I do not understand the benefit of using echo rather than just putting the text into the command itself. If you have a long command and want to save it, I would put it into a text file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM7 -script option usage

Post by fmw42 »

Magick:

Why don't either of these work? I get no error and no output!

Code: Select all

echo "-size 42x42 xc:red" | magick -verbose -script - t.png

Code: Select all

 magick -verbose -script script.txt t.png
Is there a +script so that one could do:

Code: Select all

magick -verbose -script script.txt +script t.png 
This still does not produce an output.
aperly
Posts: 4
Joined: 2015-12-26T14:44:26-07:00
Authentication code: 1151

Re: IM7 -script option usage

Post by aperly »

fmw42 wrote:Did you get an output. I did not on Mac OSX with my commands above (without the -write)?

Code: Select all

echo "-size 42x42 xc:red" | magick -verbose -script - t.png
magick: UnrecognizedOption `-size 42x42 xc:red' in "stdin" at line 1,column 1 @ fatal/magick-cli.c/ProcessScriptOptions/190.
[Windows shell behaviour?]

---

Code: Select all

echo -size 42x42 xc:red | magick -verbose -script - t.png
xc:red=>red XC 42x42 42x42+0+0 16-bit sRGB 0.000u 0:00.000
No t.png created.

---

Code: Select all

 magick -verbose -script script.txt t.png
xc:red=>red XC 42x42 42x42+0+0 16-bit sRGB 0.000u 0:00.000
No t.png created.

---
Magick's '-write' works well.


PS:
I do not understand the benefit of using echo rather than just putting the text into the command itself. If you have a long command and want to save it, I would put it into a text file.
Yeah, that was just for the test case. Easier to put a on-liner on the forum. I'm feeding 100kB commands now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM7 -script option usage

Post by fmw42 »

Glad to hear that the -write works. I suppose it has to do with the -script stopping reading from the command line. But it would seem that one should have a +script to start back reading from the command line so that this might work.

Code: Select all

echo "-size 42x42 xc:red" | magick -verbose -script - +script t.png 
aperly
Posts: 4
Joined: 2015-12-26T14:44:26-07:00
Authentication code: 1151

Re: IM7 -script option usage

Post by aperly »

Little update: I went as far as using 500MB scripts and it worked fine (for real usage, not just for stress-testing). I guess it's quite robust. :)
Post Reply