convert fails when using special filenames

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jwoelper

convert fails when using special filenames

Post 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?
Last edited by jwoelper on 2009-08-26T11:04:02-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert fails when using special filenames

Post by magick »

This works for us:
  • convert i1t_T1.tga 'i1t_T1[1024x1024].tga'
We're using ImageMagick 6.5.5-2.
jwoelper

Re: convert fails when using special filenames

Post 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'?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert fails when using special filenames

Post 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.
jwoelper

Re: convert fails when using special filenames

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert fails when using special filenames

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert fails when using special filenames

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert fails when using special filenames

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert fails when using special filenames

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jwoelper

Re: convert fails when using special filenames

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert fails when using special filenames

Post 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
jwoelper

Re: convert fails when using special filenames

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert fails when using special filenames

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply