1
votes

I'm trying to get the following command to work on Server 2003 using an ImageMagik tool called mogrify.

for %G in (.jpg, .png, .gif) do forfiles /p "C:\Images" /s /m *%G -d 0 -c "cmd /c C:\ImageMagick\mogrify.exe -resize 800x800^> -quality 80 -strip @path"

But when the mogrify tool runs for the found path it errors saying the resize arg is invalid.

mogrify.exe: InvalidArgument `80Ã╬0>': -resize @error/mogrify.c/MogrifyImageCommand/5754.

I believe the problem relates the value and that it contains ^>. The > symbol is needed to tell the tool to only downscale either width or height and I think the ^ is needed as an escape character.

Independently the command does work and the image is resized:

mogrify.exe -resize 800x800^> -quality 80 -strip "image1.jpg"

Also the command works if I remove the resize arg but of course the images are not resized:

for %G in (.jpg, .png, .gif) do forfiles /p "C:\Images" /s /m *%G -d 0 -c "cmd /c C:\ImageMagick\mogrify.exe -quality 80 -strip @path"

I've also tried variations by wrapping the value with double-quotes and escaping the ^ multiple times but nothing seems to work.

For whats worth I can get the following to work but removing ^ and adding quotes from the resize value.

cmd /c C:\ImageMagick\mogrify.exe -resize "800x800>" -quality 80 -strip image1.JPG


So to summaries how do i correctly add the resize value of 800x800> to the following command?

for %G in (.jpg, .png, .gif) do forfiles /p "C:\Images" /s /m *%G -d 0 -c "cmd /c C:\ImageMagick\mogrify.exe -resize 800x800^> -quality 80 -strip @path"

1

1 Answers

2
votes

Actually, I think the problem is that 0x80 is being converted to ASCII from hex. From the forfiles /? help message:

To include special characters in the command line, use the hexadecimal code for the character in 0xHH format (ex. 0x09 for tab). Internal CMD.exe commands should be preceded with "cmd /c".

Try capitalizing the X in -resize 800X800^>.