Page 1 of 1

Read command options from a file

Posted: 2009-08-12T23:32:43-07:00
by NeqO
Hi everybody,


I'm trying to use the convert command with many arguments. In fact I want to compose an image with dozens of other pictures.

With windows the command line size is bounded, 2'047 or 8'191 chars.

I don't want that sometime my script generates a command with more than 8'191 and the program fails.

Is there an option to take the command options from a file instead of the regular manner ?
I couldn't find it on the documentation.

I found something about conjure and MSL, but I don't really want to bother with XML right now.

Any ideas ?

Thanks

Re: Read command options from a file

Posted: 2009-08-16T19:46:30-07:00
by anthony
Reading options from a file is a proposal for Im v7 but it requires some changed in option handling.

At this time IM parses options twice, though technically it could do it in a single pass, and thus allow reading of options from a file.

Other things however also need to be resolved too for IM v7 , such as more global use of in-line percent escapes.

Re: Read command options from a file

Posted: 2009-08-16T22:36:27-07:00
by NeqO
Ok thanks,

I'll have to find another ways to compose my image then :)

Re: Read command options from a file

Posted: 2009-08-16T22:42:09-07:00
by anthony
Temporary files. MPC: image files is very fast for reading images back into memory (zero parsing time, disk file just gets mounted as memory)

Re: Read command options from a file

Posted: 2009-08-17T04:27:48-07:00
by NeqO
So you suggest something like

Code: Select all

convert img.jpg  \
balloon.gif  -geometry  +5+10  -composite \
medical.gif  -geometry +35+30  -composite \
present.gif  -geometry +62+50  -composite \
shading.gif  -geometry +10+55  -composite \
[...]
temp.mpc

convert temp.mpc  \
balloon.gif  -geometry  +5+10  -composite \
medical.gif  -geometry +35+30  -composite \
present.gif  -geometry +62+50  -composite \
shading.gif  -geometry +10+55  -composite \
[...]
final.png

rm temp.mpc
?

Re: Read command options from a file

Posted: 2009-08-17T08:48:03-07:00
by jaffamuffin
depending on just how long your command is and how long it might be, could you possibly get by by just renaming the files to 1, 2, 3, 4, 5, 6, 7, 8, etc..? You wouldn't even need the extension as imagemagick should be able to know what it is by reading the file.

That could save a lot of characters. Renaming is a fast operation. If you needed to preserve the filenames, just remember what they names were before and then rename them back afterwards...

Re: Read command options from a file

Posted: 2009-08-17T22:46:54-07:00
by anthony
Exactally.

however MPC files are saved as TWO files. The large memory mapped file and a small information file. (.mpc and .cache files). Both needs to be cleaned up.

the advantage of MPC is that it does not need any parseing when read in. It is simply written from and read directly into data memory, AS IS. Under unix it can even use 'memory map' the disk file directly into memory, so IM itself does not need to read the file!

See http://www.imagemagick.org/Usage/files/#mpc

WARNING: MPC files are only good for temporary files. They only work for the particular version of IM that wrote it. They are not for long term storage, which is why they are not commonly used.

Re: Read command options from a file

Posted: 2016-09-09T03:47:31-07:00
by spammy63
Hi .. any news on that topic ?
I found:
"Some ImageMagick command-line options may exceed the capabilities of your command-line processor. Windows, for example, limits command-lines to 8192 characters. If, for example, you have a draw option with polygon points that exceed the command-line length limit, put the draw option instead in a file and reference the file with the @ (e.g. @mypoly.txt)." Examples for that avaliable ?

I.e I want to create a layered image with explicit positional data:

layers.dat
-page +0+0 m1@1.bmp
-page +150+44 m1@2.bmp
-page +300+87 m1@3.bmp

convert @layers.dat -background rgb(10,10,200) -layers merge +repage overview.bmp

provides an error : UnableToOpenBlob

whereas the full command work sfine:
convert -page +0+0 m1@1.bmp -page +150+10 m1@2.bmp -page +300+20 m1@3.bmp -background rgb(10,10,200) -layers merge +repage overview.bmp

Unfortunatelly I don't have simply 3 images I have hundrets of them (with full path) so the windows command line length exceeds.1
The layers.dat could be calculated and written per another script during image acquisition ... (of a microscopic XY-stage).

Many thanks,

CHris

Re: Read command options from a file

Posted: 2016-09-09T04:10:34-07:00
by snibgo
Spammy63 wrote:Hi .. any news on that topic ?
Well, both v6 and v7 have script facilities. Annoyingly, they are different. (For example: v6 scripts return back to the command line, but v7 scripts don't.) What version of IM are you using?

You "layers.dat", with three lines, works fine for me, under v6.9.5-3. (The developers say it wasn't designed to work under v6, so it doesn't under v7. The replacement under v7 is "-script", which works differently.)

Re: Read command options from a file

Posted: 2016-09-09T04:20:48-07:00
by spammy63
Such a quick answer, thanks !
I use v6.9.5.3 - under windows10 - after fiddling around ist works - BUT IGNORES THE FIRST ENTRY in layers.dat - this first entry provides an error messages but the rest of the entires is processed without problems ! The following modification of layers.dat provides an error message (UnableToOpenBlob) but works so far for what I need it. Will do further tests with huge amount of image entries in layers.dat.

modified layers.dat (first line doubled:)
-page +0+0 m1@1.bmp
-page +0+0 m1@1.bmp
-page +128+0 m1@2.bmp
-page +256+0 m1@3.bmp
-page +0+96 m2@1.bmp
-page +128+96 m2@2.bmp
-page +256+96 m2@3.bmp

Strange ...
Chris

Re: Read command options from a file

Posted: 2016-09-09T04:26:18-07:00
by snibgo
On Windows 8.1, I don't get UnableToOpenBlob, and I don't need to double the first line. Is your layers.dat a text file, just plain ASCII text with no UTF or anything else?

Re: Read command options from a file

Posted: 2016-09-09T04:31:40-07:00
by spammy63
... have to test. maybe there is a problem.

Re: Read command options from a file

Posted: 2016-09-09T05:05:46-07:00
by spammy63
plain ascii .. behaviour as described.

Re: Read command options from a file

Posted: 2016-09-09T05:25:11-07:00
by snibgo
Oh dear, I was running an old version of IM. Under v6.9.5-3, "@" scripts seem to be broken. I also get an error message and the first line is ignored, then following lines work.

As I've mentioned, scripts with image options were never supposed to work under v6, so the developers may say, "tough luck".