Page 1 of 1

convert fails when using special filenames

Posted: 2009-08-26T10:56:08-07:00
by jwoelper
Hello everyone,

during the automatic generation of differently-sized pictures i noticed the following:


I left out all options to narrow down the problem, normally the image would have been resized:

convert i1t_T1.tga i1t_T1[8x8].tga (works as expected, creates i1t_T1[8x8].tga)

convert i1t_T1.tga i1t_T1[hello].tga (works as expected, creates i1t_T1[hello].tga)

convert i1t_T1.tga i1t_T1[1024x1024].tga (nothing gets created, no error message)

convert i1t_T1.tga i1t_T1\[1024x1024\].tga (nothing gets created, no error message)

convert i1t_T1.tga i1t_T1[665x665].tga (nothing gets created, no error message)

convert i1t_T1.tga i1t_T1[666x666].tga (works)

This leaves me utterly confused. Any way i try to quote or escape, convert just quits and does not create an image.

I assume this is not related to the image itself, as it does work with some output filenames and no other operations are applied.
However, when i use another, similiarily named image (like i1t_T3.tga) everything works fine.

Please let me know if I should provide example images.

ImageMagick 6.4.0 07/27/08 Q16 on Fedora 10 x64, the same on OSX 10.5, 6.5.5-0 via macports.

All the best,

Johann Woelper


*** edit:
should have thought of that before, but -verbose gives additional insight:

convert -verbose i1t_T1.tga i1t_T1\[666x666\].tga
i1t_T1.tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 2.72476mb
i1t_T1.tga=>i1t_T1[666x666].tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 3.00002mb
(all ok)

convert -verbose i1t_T1.tga i1t_T1\[665x665\].tga
i1t_T1.tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 2.72476mb
i1t_T1.tga=>i1t_T15.tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 3.00002mb 0.020u 0:02

So it actually resolves '\[665x665\]' to '15', and jolly overwrites my i1t_T15.tga, which, by chance, i had in the same folder...
Is this expected behaviour?

Re: convert fails when using special filenames

Posted: 2009-08-26T11:02:53-07:00
by magick
This works for us:
  • convert i1t_T1.tga 'i1t_T1[1024x1024].tga'
We're using ImageMagick 6.5.5-2.

Re: convert fails when using special filenames

Posted: 2009-08-26T11:10:03-07:00
by jwoelper
magick wrote:This works for us:
  • convert i1t_T1.tga 'i1t_T1[1024x1024].tga'
We're using ImageMagick 6.5.5-2.
Hi!

Thanks for the quick reply. I guess this works because you are lacking the files i have (sorry for not letting you know: my directory contains a large number of sequentially numbered files, like i1t_T1.tga, i1t_T2.tga, i1t_T3.tga...)

so, if i run the command you suggested, i get:
convert i1t_T1.tga 'i1t_T1[1024x1024].tga'

i1t_T1.tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 2.72476mb
i1t_T10.tga TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 3.00002mb
i1t_T11.tga TGA 16x16 16x16+0+0 DirectClass 8-bit 786b
i1t_T12.tga[0] TGA 128x128 128x128+0+0 DirectClass 8-bit 112.035kb
i1t_T12.tga[1] TGA 128x128 128x128+0+0 DirectClass 8-bit 112.035kb
i1t_T1.tga=>i1t_T14.tga[0] TGA 1024x1024 1024x1024+0+0 DirectClass 8-bit 6.11019mb


i read the man page, and i assumed the brackets should only be recognized if they are behind the extention, like 'convert catalogue.pdf[10] page.tif'?

Re: convert fails when using special filenames

Posted: 2009-08-26T12:01:24-07:00
by fmw42
brackets refer to a subsection on the input image or to an image frame (sequence), but appear AFTER the suffix

see Selecting an Image Region on http://www.imagemagick.org/script/comma ... .php#input

So I suspect you may have trouble with filenames that have [ ... ] in the primary part of the filename prior to the suffix.

Don't know if putting quotes around the filename will help.

Re: convert fails when using special filenames

Posted: 2009-08-26T12:31:21-07:00
by jwoelper
fmw42 wrote:brackets refer to a subsection on the input image or to an image frame (sequence), but appear AFTER the suffix

see Selecting an Image Region on http://www.imagemagick.org/script/comma ... .php#input

So I suspect you may have trouble with filenames that have [ ... ] in the primary part of the filename prior to the suffix.

Don't know if putting quotes around the filename will help.
I see... so there would be no way handling images that have brackets in the filename? Quoting does not help... is there any other method of escaping the brackets?

All the best,

Johann

Re: convert fails when using special filenames

Posted: 2009-08-26T12:33:27-07:00
by fmw42
if on unix, you could try

image\[8x8\].gif

but if quotes does not work, i doubt this will work. But I am no expert on these things.

Re: convert fails when using special filenames

Posted: 2009-08-26T18:01:16-07:00
by anthony
the [..] is a special syntax to IM on input only if it is AFTER the suffix

However [..] is special to most command line shells, such as BASH.
it means any ONE charcater in the backaets appear here.

That is xyzzy[192].txt
will look for the files xyzzy1.txt xyzzy2.txt xyzzy9.txt (order made alphabetical)

to prevent the shell treating the [..] as special you MUST quote or backslash escape the brackets. NOTE the BASH shell also treat (..) and {..} as special too!

Re: convert fails when using special filenames

Posted: 2009-08-26T18:08:33-07:00
by fmw42
Anthony,

so for my own edification, do you quote the whole filename or just the brackets


'filename[8x8].jpg'


or

filename'[8x8]'.jpg

or something else

Re: convert fails when using special filenames

Posted: 2009-08-26T18:46:16-07:00
by anthony
I generally quote the whole filename if it is needed. But for IM input modifications I usually only quote the modification.

Code: Select all

   convert  'input_[8x8]_image.jpg' ...

   convert  input_image.jpg'[100x100+20+20]' ...
It really only matters if you have special characters in the filename. OR you are using a variable to hold the filename.

Re: convert fails when using special filenames

Posted: 2009-08-27T00:57:28-07:00
by jwoelper
anthony wrote:I generally quote the whole filename if it is needed. But for IM input modifications I usually only quote the modification.

Code: Select all

   convert  'input_[8x8]_image.jpg' ...

   convert  input_image.jpg'[100x100+20+20]' ...
It really only matters if you have special characters in the filename. OR you are using a variable to hold the filename.

Hi! Thanks for the example. However, this still does not work.

As I wrote above, the command

Code: Select all

convert -verbose i1t_T1.tga 'i1t_T1[1024x1024].tga'
produces
i1t_T1.tga TGA 1024x1024 1024x1024+0+0 8-bit DirectClass 4mb
i1t_T10.tga TGA 1024x1024 1024x1024+0+0 8-bit DirectClass 4mb
i1t_T11.tga TGA 16x16 16x16+0+0 8-bit DirectClass 1.02kb
i1t_T12.tga[0] TGA 128x128 128x128+0+0 8-bit DirectClass 128kb
i1t_T12.tga[1] TGA 128x128 128x128+0+0 8-bit DirectClass 128kb

and, as you suggested,

Code: Select all

convert -verbose i1t_T1.tga i1t_T1'[1024x1024]'.tga
results in:

i1t_T1.tga TGA 1024x1024 1024x1024+0+0 8-bit DirectClass 4mb
i1t_T10.tga TGA 1024x1024 1024x1024+0+0 8-bit DirectClass 4mb
i1t_T11.tga TGA 16x16 16x16+0+0 8-bit DirectClass 1.02kb
i1t_T12.tga[0] TGA 128x128 128x128+0+0 8-bit DirectClass 128kb
i1t_T12.tga[1] TGA 128x128 128x128+0+0 8-bit DirectClass 128kb
i1t_T1.tga=>i1t_T14.tga[0] TGA 1024x1024 1024x1024+0+0 8-bit DirectClass 8.125mb 0.130u 0:02

My folder contains a sequence of i1t_T(1-60).tga

regards,

Johann

Re: convert fails when using special filenames

Posted: 2009-08-27T07:59:13-07:00
by fmw42
stupid question, but why are you putting such brackets on output filenames?

if you must do something like that, then could you not just use a hyphen or underscore as a separator?

convert -verbose i1t_T1.tga i1t_T1_1024x1024.tga

Re: convert fails when using special filenames

Posted: 2009-08-27T08:09:09-07:00
by jwoelper
fmw42 wrote:stupid question, but why are you putting such brackets on output filenames?

if you must do something like that, then could you not just use a hyphen or underscore as a separator?

convert -verbose i1t_T1.tga i1t_T1_1024x1024.tga

Well you're so right. Unfortunately, some proprietary software forced these filenames upon us. Of course i could rename the files (and that is what I did) but I do not think the way Imagemagick handles the filename is expected. So, as I am trying to help improve this wonderful software, I thought I should post this. Or, at least, if somebody runs into a similiar problem, she or he could see that brackets in filenames cause some weird results.

All the best

Johann

Re: convert fails when using special filenames

Posted: 2009-08-27T21:04:40-07:00
by anthony
I would agree that the brackets should work as expected. If the shell is not getting in the way and the quoting does prevent that, then I can't see why IM doesn't output brackets!

On output filename the only thing IM is currently looking for (as far as I know) is
%d as a printf format something like %03d OR a %[filename:string] See...
http://www.imagemagick.org/Usage/files/#save_escapes

so perhaps the %[...] handling is being a little over zelious and doing [...] as well.