Processing of @-file

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Processing of @-file

Post by snibgo »

Windows7, IM v6.8.5 (and earlier).

There seems to be a bug in the handling of "@" on the command line. Briefly: when the filename starts with a drive (like "h:"), convert doesn't process the file correctly.

My command is:

Code: Select all

"%IMG685%convert" h:\farmThing\cl_temp\Redfile1.png @h:\farmThing\cl_temp\crop1.txt NULL:
where crop1.txt contains this:

Code: Select all

( +clone -crop 64x54+0+0 +repage -write h:\farmThing\cl_temp\crop_R5_0.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_0.txt +delete )
( +clone -crop 64x54+64+0 +repage -write h:\farmThing\cl_temp\crop_R5_1.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_1.txt +delete )
( +clone -crop 64x54+128+0 +repage -write h:\farmThing\cl_temp\crop_R5_2.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_2.txt +delete )
( +clone -crop 64x54+192+0 +repage -write h:\farmThing\cl_temp\crop_R5_3.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_3.txt +delete )
( +clone -crop 64x54+256+0 +repage -write h:\farmThing\cl_temp\crop_R5_4.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_4.txt +delete )
( +clone -crop 64x54+320+0 +repage -write h:\farmThing\cl_temp\crop_R5_5.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_5.txt +delete )
( +clone -crop 64x54+0+54 +repage -write h:\farmThing\cl_temp\crop_R5_6.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_6.txt +delete )
( +clone -crop 64x54+64+54 +repage -write h:\farmThing\cl_temp\crop_R5_7.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_7.txt +delete )
( +clone -crop 64x54+128+54 +repage -write h:\farmThing\cl_temp\crop_R5_8.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_8.txt +delete )
( +clone -crop 64x54+192+54 +repage -write h:\farmThing\cl_temp\crop_R5_9.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_9.txt +delete )
( +clone -crop 64x54+256+54 +repage -write h:\farmThing\cl_temp\crop_R5_10.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_10.txt +delete )
( +clone -crop 64x54+320+54 +repage -write h:\farmThing\cl_temp\crop_R5_11.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_11.txt +delete )
( +clone -crop 64x54+0+108 +repage -write h:\farmThing\cl_temp\crop_R5_12.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_12.txt +delete )
( +clone -crop 64x54+64+108 +repage -write h:\farmThing\cl_temp\crop_R5_13.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_13.txt +delete )
( +clone -crop 64x54+128+108 +repage -write h:\farmThing\cl_temp\crop_R5_14.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_14.txt +delete )
( +clone -crop 64x54+192+108 +repage -write h:\farmThing\cl_temp\crop_R5_15.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_15.txt +delete )
( +clone -crop 64x54+256+108 +repage -write h:\farmThing\cl_temp\crop_R5_16.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_16.txt +delete )
( +clone -crop 64x54+320+108 +repage -write h:\farmThing\cl_temp\crop_R5_17.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_17.txt +delete )
( +clone -crop 64x54+0+162 +repage -write h:\farmThing\cl_temp\crop_R5_18.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_18.txt +delete )
( +clone -crop 64x54+64+162 +repage -write h:\farmThing\cl_temp\crop_R5_19.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_19.txt +delete )
( +clone -crop 64x54+128+162 +repage -write h:\farmThing\cl_temp\crop_R5_20.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_20.txt +delete )
( +clone -crop 64x54+192+162 +repage -write h:\farmThing\cl_temp\crop_R5_21.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_21.txt +delete )
( +clone -crop 64x54+256+162 +repage -write h:\farmThing\cl_temp\crop_R5_22.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_22.txt +delete )
( +clone -crop 64x54+320+162 +repage -write h:\farmThing\cl_temp\crop_R5_23.miff -format "%[fx:standard_deviation]" -write info:h:\farmThing\cl_temp\sd1_R5_23.txt +delete )
I get error messages:

Code: Select all

convert.exe: unable to open image `(': No such file or directory @ error/blob.c/
OpenBlob/2641.
convert.exe: no decode delegate for this image format `(' @ error/constitute.c/R
eadImage/550.
convert.exe: unable to open image `+clone': No such file or directory @ error/bl
ob.c/OpenBlob/2641.
convert.exe: no decode delegate for this image format `+clone' @ error/constitut
e.c/ReadImage/550.
etc. Putting quotes around "@h:\farmThing\cl_temp\crop1.txt" or just the filename doesn't help.

Moving crop1.txt to directory "temp\" and executing this...

Code: Select all

"%IMG685%convert" h:\farmThing\cl_temp\Redfile1.png @temp\crop1.txt NULL:
... works with no problem, creating the cropped files and their standard deviations.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Processing of @-file

Post by snibgo »

I should have provided a simple example. Here it is.

The file d:\web\im\temp\twiddle.txt contains:

Code: Select all

( +clone -resize 200% )
When my current directory is d:\web\im, the first of these commands works, and the second doesn't:

Code: Select all

"%IMG%convert" rose: @temp\twiddle.txt -delete 0 r.png

"%IMG%convert" rose: @d:\web\im\temp\twiddle.txt -delete 0 r.png
The @-file can't contain arbitrary IM commands, but anything that begins with "("seems okay.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Processing of @-file

Post by anthony »

IMv7 is providing a -script {file} option that will read IM commands from the given script.
That is one of the key parts of the new Script and Pipelined Control features of IMv7


[Soap Box

The file is read using a syntax that is basically the same as the UNIX shell, in terms of quote and line continuation handling. That means that a the command line options (for UNIX), can essentially be placed in that file without change, and it should work as expected.

For example...

Code: Select all

magick -size 100x100 xc:red \
       \( rose: -rotate -90 \) \
       +append   show:
can be converted into a scripting file.

Code: Select all

#!/bin/env magick-script
#
# Magick Script
#
-size 100x100 xc:red
( rose: -rotate -90 )
+append   -write show:
and executed using the command

Code: Select all

  magick -script magick_script_file
Or because of the special 'she-bang' magic comment at the top, simply made executable and run as a script command.

I am wanting to get a 'DOS' version of a simply run script... the current iteration of which is

Code: Select all

@magick -script %~dpnx0 %*
@GOTO :EOF
# comment
-size 100x100 xc:red
( rose: -rotate -90 )
+append   -write show:
But I have had reports that it does not work... I am not a DOS/PC user.


The -script {file} option will be able to return, so you could create scripts for doing very complex things and run them in normal command line use.. As such with a library of such script you will be able to do somthing like this.

Code: Select all

magick  input_image.png   -script make_fancy.mgk    -script shadow.mgk   output_image.png

At this time the scripting facility does not have argument handling (where it reads filenames, or extra magick/convert options after the -script call). Nor have I created many examples of its use.

The above is about where it is at, for the moment.

Right now I am working on expansions to the percent escape system (allow the use of FX mathematics and other simple string manipulation in the option arguments).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Processing of @-file

Post by snibgo »

"show:" hasn't worked on Windows for ages. If I replace that with a filename, such as "r.png", it works fine for me, on an old version of magick (Version: ImageMagick 7.0.0-0 2013-03-17).

It even works if I put the batch file on a different drive. Now, if only v6 could process drive letters in @-files ...
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Processing of @-file

Post by anthony »

The @file syntax in IMv6 and IMv7 is however NOT for options. You can not read and process options from it. Its purpose if to provide a list of image file names. not options.

It is processed by the image read functions, and has no connection with normal option processing.
To allow it to do this would probably represent a 'security hole'.

The other way is to 'generate' the command on the fly. that is easy in UNIX, but probably not easy in DOS, where you would probably need to have a script generate and execute another script.


In IMv7 I also added a -read option for a explict read operator. The -read is different to an implict read in that the argument will always be thought of as a image filename (and passed to the ReadImage handler), rather than as a command line argument does not match a known option. This -read operator will likely become vital when "mogrify" is converted to the new CLI handling system. That is allow it to do 'multi-image handling' while batch processing a list of input images, something it currently can not do.


Hmmm...
The problem may be the ':' in the filename. IM may be thinking that it is a 'prefix' of some kind. that is it is seeing @h: as a coder prefix, rather than just the '@' as a read image list.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Processing of @-file

Post by snibgo »

Yes, when I @D:temp\something.txt in v6.7.9, I get

convert.exe: unable to open module file `C:\Program Files (x86)\ImageMagick-6.7.9-Q16\modules\coders\IM_MOD_RL_@D_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/683.

But if I don't have a drive letter and colon, it works fine in 6.7.9, 6.8.3, 6.8.4 and 6.8.5.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Processing of @-file

Post by anthony »

That to me is a bug... no coder should be involved with that reading of an @file of images, unless the coder is specified inside that file.

It is like the order of handling @ files and that for coders is wrong.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply