Page 1 of 2

identify fails silently on filenames with %d

Posted: 2012-09-04T10:51:25-07:00
by teleshoes
"identify" on linux {ubuntu 12.10 amd64 3.5.0-13-generic} doesnt output anything on filenames that have "%d" in them.

/tmp/a$ md5sum *
0115516fc61d2d1e6f094c22ac95051e a-d.png
0115516fc61d2d1e6f094c22ac95051e a%d.png
/tmp/a$ identify a-d.png
a-d.png PNG 80x80 80x80+0+0 8-bit DirectClass 581B 0.000u 0:00.000
/tmp/a$ identify a%d.png
/tmp/a$ identify a-d.png
a-d.png PNG 80x80 80x80+0+0 8-bit DirectClass 581B 0.000u 0:00.000
/tmp/a$ identify --version
Version: ImageMagick 6.7.7-10 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T11:33:29-07:00
by fmw42
Did you try putting the filename in quotes. Also perhaps upgrade your version of IM.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T18:53:05-07:00
by anthony
The %d is a special interpretation (both read and write).

Use %%d instead.


I have a plan to add a 'security option' in IMv7 to disable various filename modifications IM does, such as this. (another is the the coder prefix handling). That is make tell IM to treat filenames and perhaps arguments as being more 'literal', especially in IMv7 where % escapes are also used for almost ALL arguments (operation arguments already do this in "magick")

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:07:21-07:00
by teleshoes
Yes, i tried quoting the files, but you realize, thats handled by the SHELL, not by imagemagick; imagemagick receives the argument as the SAME STRING whether its quoted or not. {% is not special in bash.}

thanks for the help, but this is actually a bug, not my shell interpolation misunderstanding.


as for the %d's being legitimate escapes in the filename, no, thats not true, and %% doesnt help it.

heres a table of what works and doesnt {quoted, or unquoted, or escaped}, extracted from my code below:

WORKS:
a.png
a
%
d%
a%!d.png
a%b.png

DOES NOT WORK:
a%d.png
a%%d.png
a%d
%da
%d
%%d
%d.png


here is the output proving that shell interpolation and quoting of arguments is NOT the problem:

Code: Select all

wolke:/tmp/a$ cp a.png a%d.png
wolke:/tmp/a$ identify a.png 
a.png PNG 80x80 80x80+0+0 8-bit DirectClass 8.59KB 0.000u 0:00.000
wolke:/tmp/a$ identify a%d.png 
wolke:/tmp/a$ identify 'a%d.png'
wolke:/tmp/a$ identify a\%d.png
wolke:/tmp/a$ identify "a%d.png"
wolke:/tmp/a$ identify "a%d.png"
wolke:/tmp/a$ identify a.png 
a.png PNG 80x80 80x80+0+0 8-bit DirectClass 8.59KB 0.000u 0:00.000
here is the output showing that %% doesnt help:

Code: Select all

wolke:/tmp/a$ cp a.png a%d.png
wolke:/tmp/a$ identify a.png 
a.png PNG 80x80 80x80+0+0 8-bit DirectClass 8.59KB 0.000u 0:00.000
wolke:/tmp/a$ identify a%%d.png
wolke:/tmp/a$ identify a.png 
a.png PNG 80x80 80x80+0+0 8-bit DirectClass 8.59KB 0.000u 0:00.010

here is the output showing what WORKS and what does NOT work:

Code: Select all

wolke:/tmp/a$ for x in a%d.png a%\!d.png a %%d %d.png a%b.png %da % a%%d.png d% a%d %d
> do
>   cp a.png $x
>   identify $x | grep PNG > /dev/null && echo GOOD: $x || echo BAD: $x
> done
BAD: a%d.png
GOOD: a%!d.png
GOOD: a
BAD: %%d
BAD: %d.png
GOOD: a%b.png
BAD: %da
GOOD: %
BAD: a%%d.png
GOOD: d%
BAD: a%d
BAD: %d

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:09:37-07:00
by teleshoes
also, as for the version: 2012-08-17 is recent enough, yes?

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:15:59-07:00
by fmw42
This works on IM 6.7.9.3 Q16, though without the -verbose it still returns no informaton:

identify -verbose 1%d.jpg

Also creating my own script with specific string format returns the information I requested.


ids 1%d.jpg
1%d.jpg[0] DirectClass sRGB channels=srgb depth=8 min=0 max=1 mean=0.649543 std=0.300478 117501B bytes

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:18:29-07:00
by teleshoes
fmw42 wrote:This works on IM 6.7.9.3 Q16, though without the -verbose it still returns no informaton:

identify -verbose 1%d.jpg
oh snap, me too. ok, so its an error on the output somehow. thanks for that! i now have a solution to the problem immediately at hand.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:20:27-07:00
by teleshoes
just to be crystal clear, THIS IS STILL A BUG, and confirmed by another user independently.
in fact, it means i cant use or rely upon identify without passing the verbose flag in.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:20:47-07:00
by fmw42
If it works with -verbose and with my own custom version, then it should work with just identify. So I would agree that there is an apparent bug.

Perhaps you should repost to the Bugs forum.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:26:34-07:00
by fmw42
This also works

convert 1%d.jpg info:

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:30:01-07:00
by teleshoes
fmw42 wrote:This also works

convert 1%d.jpg info:
aaaand you just saved me from writing a wrapper to simulate the output from -verbose. thanks again!

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:38:42-07:00
by fmw42
I would still suggest you repost to the bugs forum.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T20:41:24-07:00
by teleshoes
crap, this isnt the bug forum. thanks, didnt realize because of the redirect for signing up to the forums.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T21:41:28-07:00
by anthony
teleshoes wrote:Yes, i tried quoting the files, but you realize, thats handled by the SHELL, not by imagemagick; imagemagick receives the argument as the SAME STRING whether its quoted or not. {% is not special in bash.}
No % is not special in shell. never said it was.

%d (and only %d, with optional numbers between the % and the d, such as %03d ) is special in Image reading to real numbered files. Actually I have not documented it very well in Image file reading either. But it is mentioned in the first read-modifier, section
http://www.imagemagick.org/Usage/files/#read_mods
You can also get IM to read images based on a list of numbers. For example..

Code: Select all

  convert 'image_%03d.png[5-7]' ...
will read in the files "image_005.png", "image_006.png", and "image_007.png". With this method you can not use a negative index.
So "file_%d.png[0-9]" will first try to read "file_0.png" then "file_1.png", and so on until it does not find a file.

It is a IM 'feature' but for your case it is a bug. It probably should ignore %d if no [...] component has been provided.

Re: identify fails silently on filenames with %d

Posted: 2012-09-04T22:28:34-07:00
by teleshoes
anthony wrote:No % is not special in shell. never said it was.
i was referring to the earlier poster who suggested i quote it.
anthony wrote:It is a IM 'feature' but for your case it is a bug. It probably should ignore %d if no [...] component has been provided.
this is not a case of a poorly documented feature with a distinct workaround, but behaviour that is explicitly different than the stated behaviours.

in fact, the bug almost certainly isnt in the filename reading. it seems to be in the output, since the -verbose flag makes it work correctly.

{also, this is an example of a TERRIBLE feature. this is easily accomplished with a wrapper. the wrapper could be a separate tool, with explicit semantics: e.g.: identify -verbose `expand a%d.png 1 2 5 3 15 51`}