You are not logged in.

#1 14 Mar 2019 10:41

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Command doesn't work properly in a script with variables

I'm back for more help, because once again, a command that SHOULD work, doesn't.

Using the "Identify" command from the ImageMagick package in the follow syntax;

identify -format "%T\n" test.gif[0] >>speed.txt

Will write the delay value of the first frame of an animated GIF to the file "speed.txt"

However when I try to put that command into a loop in a batch file to process all GIF files in a directory, it fails completely;

for %%F in (*.gif) do identify -format "%T\n" %%F[0] >>speed.txt

The output of the script shows as follows;

for %F in (*.gif) do (identify -format "F[0] >>speed.txt )

The parameters get omitted, the variable for the filename is written as "F[0] and nothing gets written to the text file.

This sort of stuff works with other commands so I have absolutely no clue why it doesn't work with this particular command.

Anyone?

Offline

#2 14 Mar 2019 11:00

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Command doesn't work properly in a script with variables

I think that the %T (the "%" specifically) is interfering with variable expansion and the for loop -- "%" is a special character that needs to be escaped.

This should work a little better

for %%F in (*.gif) do identify -format "%%T\n" %%F[0] >>speed.txt

cmd | *sh | ruby | chef

Offline

#3 15 Mar 2019 07:44

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Re: Command doesn't work properly in a script with variables

bluesxman wrote:

I think that the %T (the "%" specifically) is interfering with variable expansion and the for loop -- "%" is a special character that needs to be escaped.

Yes it does, thank you. smile

I was under the impression that the "%" was protected since it's inside quotes.

It looks like my efforts to figure this out were wasted though. The idea was to fix animated GIFs that have corruption in Irfanview by extracting all the frames, getting the frame rate (I know animated GIFs can have different delays between the frames, but I've never seen one) and then re-assembling the frames into a new file. Unfortunately, this causes the new file to be 6-7x larger than the original, which I consider an unacceptable outcome.

I tried the generic Optimize option, but that didn't help. There are probably some options somewhere in ImageMagick that can make them smaller, but since it's designed to operate on all images and even video formats, and I'm not an expert on the GIF format and tricks that can be used to make them smaller, it looks like more work than it's worth. I also tried GIF Animator's optimize option, but that was only able to get the new file down to 2x the original size by mangling the colors. sad

Offline

Board footer

Powered by