Possible bug with filename handling (Windows x86)
Posted: 2019-08-07T08:18:41-07:00
I don't know if this is a legitimate bug or just some quirk of the command line that I'm not aware of. It seems like a bug to me.
To start with, I have an old system with WinXP on it, so I'm using this release;
ImageMagick-7.0.8-59-portable-Q16-x86.zip
I've been trying to write a script that will go through a directory full of unknown image files and rename them based on their actual width. Since the directory may contain GIF files with multiple frames, the only reliable way to get the width is to tell it to only look at the first frame. Otherwise the width might be reported as "450450450450450", etc. The problem is that the command line fails if the filename happens to contain "%%" and you include the option to only check the first frame.
For example, these work;
If the name contains "%%", the command will work if you leave off the "[0]";
However if you include "[0]" either inside or outside of the quotes, the command fails;
In order to make them work, you have to add an extra "%";
Since this is being used inside a script, I don't know ahead of time what the filenames will contain. While I admit that it's unlikely that any filename will contain multiple "%"s I can't rule it out. I thought that enclosing the filenames in quotes would protect them, but for some reason, the addition of "[0]" seems to nullify the effect of the quotes and it thinks the percent signs are part of the parameters.
I'm inclined to consider this a bug since it has no problem with the filename when you omit "[0]", no matter what (legal) characters it contains. I wouldn't think that a parameter (flag, whatever) to tell it to only look at the first frame of a file would change how it handles the filename.
To start with, I have an old system with WinXP on it, so I'm using this release;
ImageMagick-7.0.8-59-portable-Q16-x86.zip
I've been trying to write a script that will go through a directory full of unknown image files and rename them based on their actual width. Since the directory may contain GIF files with multiple frames, the only reliable way to get the width is to tell it to only look at the first frame. Otherwise the width might be reported as "450450450450450", etc. The problem is that the command line fails if the filename happens to contain "%%" and you include the option to only check the first frame.
For example, these work;
Code: Select all
Identify -format %w "Test.gif"[0]
Identify -format %w "Test.gif[0]"
Code: Select all
Identify -format %w "T%%est.gif"
Code: Select all
Identify -format %w "T%%est.gif"[0]
Identify -format %w "T%%est.gif[0]"
Code: Select all
Identify -format %w "T%%%est.gif"[0][/b]
Identify -format %w "T%%%est.gif[0]"[/b]
I'm inclined to consider this a bug since it has no problem with the filename when you omit "[0]", no matter what (legal) characters it contains. I wouldn't think that a parameter (flag, whatever) to tell it to only look at the first frame of a file would change how it handles the filename.