Page 1 of 1

Issue using %d operator and filename:label

Posted: 2013-02-15T13:03:31-07:00
by cuddlyogre
I am attempting to output all of the frames of an animated gif to an individual file, while preserving the frame's delay time. This is my command:

Code: Select all

convert.exe image.gif -coalesce -set filename:label %T "frame_%02d_%[filename:label]0.png"
My problem is that when I use %02d I get file names like this:

Code: Select all

image_00_%[70.png
or when I use %07d I get:

Code: Select all

image_0000070.png
When I use %04d I get:

Code: Select all

image_0000_70.png
which is what I want, but I am puzzled as to what is happening here.

It appears that 4 leading zeros are required in cases like this or else it starts either reading or eating whatever is in the following %[filename:whatever]. It begins behaving normally when it encounters non-variable text again. Is there something I am not doing right?

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T13:13:55-07:00
by snibgo
"convert.exe" means you are running on Windows, correct? If your commands are in a batch file, you need to double the "%" signs, because "%" on its own is interpreted by the Windows shell in a special way.

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T13:24:04-07:00
by cuddlyogre
I am running it through the command prompt directly. When I use double percent signs, the exported file names get all screwed up or the command won't complete at all. I feel there is more to it than that.

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T14:13:05-07:00
by cuddlyogre
Not sure what is happening, but I have found a bit of a workaround. The minimum amount of leading zeros you can have seems to be four in these cases and for each extra leading zero you want, you have to add 1 zero to %d and increment the number of leading zeros by the number of zeros you added.

%04d (minimum that works as expected) gives:

Code: Select all

image_0000_7.png
%005d gives:

Code: Select all

image_00000_7.png
%0006d gives:

Code: Select all

image_000000_7.png
...and so on.

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T15:21:31-07:00
by snibgo
Weired. What version of IM, and what platform?

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T18:05:41-07:00
by fmw42
I am not a windows user, but try

convert.exe image.gif -coalesce -set filename:label "%%T" "frame_%%02d_%%[filename:label]0.png"

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T18:34:33-07:00
by snibgo
The OP is running from the command line so % should not be doubled as they would both be passed to IM convert, although this is generally harmless

If an environment variable called T already exists, that would cause a problem. Issue the command "set T=" to ensure it doesn't exist.

Trying this ...

Code: Select all

convert.exe image.gif -coalesce -set filename:label %T "frame_%02d_%[filename:label]0.png"
... (in 6.7.9, 6.8.2 and 6.8.3 on Windows 7), it seems IM is happy to have either "%02d" or "%[filename:label]" in the output name, but not both.

Re: Issue using %d operator and filename:label

Posted: 2013-02-15T21:10:27-07:00
by cuddlyogre
I am using 6.8.3 on Windows 7 and I have verified that "T" is not set as an environment variable. If I am reading you properly snibgo, it is a replicatable bug and not user error. In that case, I will file a bug report.

Your help was much appreciated.