Page 1 of 1

Using -density in a loop in a batch in Windows 10

Posted: 2018-02-22T01:08:48-07:00
by Jean-Pierre Coulon
magick chunk.tif -density %%[fx:w/8.26] chunk.pdf works fine but I want to make a loop for a series of images with this batch:

for /l %%a in (1,1,%1) do (
call magick p%%a.tif -density %%[fx:w/8.26] q%%a.pdf
)

and when I type mybatch 5 I obtain magick: invalid argument for option 'density' 'w/8.26]' ar CLI arg 2 @error/operation.c/CLISettingOptionInfo/726 at every image.

It seems the argument of -density is cropped in this context. Why? If there is no loop magick works fine in a batch.

Re: Using -density in a loop in a batch in Windows 10

Posted: 2018-02-22T01:33:55-07:00
by snibgo
"call" is used to call a batch (BAT) script. magick.exe is a binary program, not a BAT script.

Re: Using -density in a loop in a batch in Windows 10

Posted: 2018-02-22T01:48:14-07:00
by Jean-Pierre Coulon
Thanks. But in a more complicated case I have to use call for the parameter substitution to work well, e.g.

for /l %%a in (1,1,%1) do (
set /a mypage = "2*%%a +1"
call magick p%%mypage%.tif q%%mypage%%.pdf
)

This fails if you remove "call".

Re: Using -density in a loop in a batch in Windows 10

Posted: 2018-02-22T02:09:42-07:00
by snibgo
I've never used Windows 10. (I use 8.1) In all previous versions, "call" is wrong for running an exe program.

For your magick line, you should use delayed expansion of the variable "mypage" (because it has to be expanded in each loop repetition, not just once at the start). So the script looks like this:

Code: Select all

setlocal enabledelayedexpansion

for /l %%a in (1,1,%1) do (
  set /a mypage = "2*%%a +1"

  magick p!mypage!.tif -density %%[fx:w/8.26] q!mypage!.pdf
)

Re: Using -density in a loop in a batch in Windows 10

Posted: 2018-02-22T03:07:40-07:00
by Jean-Pierre Coulon
Thanks.