Page 1 of 2

spaces and annotations in filenames

Posted: 2018-02-18T16:52:48-07:00
by nagame
I searched on Google without finding the answer to this question : how to use annotations in special filenames ?
ex: identify -format '%w %h' 'file name with spaces : and others caracters (1).jpg[0]'

systematically, I get in error "No such file or directory @ error/blob.c/OpenBlob/3146."

the only solution I found (but I do not like) :
cat 'file name with spaces : and others caracters (1).jpg' | identify -format '%w %h' -[0]

thank you very much ! (sorry for my English)

Re: spaces and annotations in filenames

Posted: 2018-02-18T18:28:53-07:00
by snibgo
You should say what version of IM you are using. Also say what shell you are using (eg bash, Windows CMD, etc) as they all behave differently. Some filesystems won't allow colons (":") in filenames.

Do you have a file with that name?

Re: spaces and annotations in filenames

Posted: 2018-02-19T07:13:12-07:00
by nagame
Hello,

thank you for your reply. I use Bash with ImageMagick 7.0.7-11

You can reproduce the error with any file and even without the ":" character. I do not know if it's a bash bug or an ImageMagick bug. Use of a name with space and quotation marks work well IF there is no annotation "[0]". If there is "[0]", ImageMagick will scan the name and the error will appear.

identify -format '%w %h' 'file name with spaces.jpg'
No problem

identify -format '%w %h' 'file name with spaces.jpg'[0]
identify -format '%w %h' 'file name with spaces.jpg[0]'
Problem

Re: spaces and annotations in filenames

Posted: 2018-02-19T07:45:10-07:00
by snibgo
With v7, I think you should use "magick identify", not just "identify".

Strange. Those work fine for me, IM v7.0.3-5 (and v6.9.5-3) on Cygwin bash on Windows 8.1.

Code: Select all

$ magick identify -format '%w %h' 'file name.jpg'[0]
70 46
Alan@Fiona /cygdrive/f/web/im
$ magick identify -format '%w %h' 'file name.jpg[0]'
70 46

Re: spaces and annotations in filenames

Posted: 2018-02-19T13:17:53-07:00
by nagame
you are right, after verification the problem is the character ":"

Code: Select all

$ identify -format '%w %h' 'file name : test2.jpg'[0]
identify: unable to open image 'file name : test2.jpg[0]': No such file or directory @ error/blob.c/OpenBlob/3146.
sorry for my test error.

Re: spaces and annotations in filenames

Posted: 2018-02-19T13:19:22-07:00
by nagame
the ":" character is not allowed in Windows file names but allowed in Unix systems like...

Re: spaces and annotations in filenames

Posted: 2018-02-20T16:37:55-07:00
by fmw42
There is no point in accessing layer [0] of a jpg file, since JPG does not allow layers. However, it should not hurt if you use the same code for gif or tiff or PDF which allow layers/pages/frames

Re: spaces and annotations in filenames

Posted: 2018-02-21T06:12:47-07:00
by nagame
Okay. But that does not answer my question about the bug.
I just did a new test with a PDF :

Code: Select all

identify -format '%w %h' 'file name : test2.PDF'[0]
identify: unable to open image 'file name : test2.PDF[0]': No such file or directory @ error/blob.c/OpenBlob/3146.

Re: spaces and annotations in filenames

Posted: 2018-02-21T10:28:09-07:00
by fmw42
I do not understand

identify -format '%w %h' 'file name : test2.PDF'[0]

Is filename : test2.pdf the name of your file including the spaces and colon?

Some OS do not allow colons in filenames.

Try using double quotes.

Re: spaces and annotations in filenames

Posted: 2018-02-21T11:06:36-07:00
by snibgo
The real problem is that IM interprets characters before the colon as a format type, as in "PNG:abc.png", even if those characters aren't a format type.

Re: spaces and annotations in filenames

Posted: 2018-02-21T11:07:06-07:00
by fmw42
This works fine for me on IM 6.9.9.35 Q16 Mac OSX Sierra using double quotes.

Code: Select all

identify -format "%wx%h\n" "lena copy.png[0]"
My unix does not allow : in filenames.

Re: spaces and annotations in filenames

Posted: 2018-02-21T14:09:04-07:00
by nagame
Thank you for your answers.

snibgo : no, because the colon alone works well (without [0])

Code: Select all

identify -format '%w %h' 'filename:.PDF'
600 450
=> OK

If we add [0], it does not work anymore

Code: Select all

identify -format '%w %h' 'filename:.PDF'[0]
identify: unable to open image 'filename:.PDF[0]': No such file or directory @ error/blob.c/OpenBlob/3146.
=> NOK

The bug is the use of colon AND [0] in file names

@fmw42 : Yes but Linux accepts colon in file names :-/ I tried with double quotes, the bug is still true :

Code: Select all

identify -format '%w %h' "filename:.PDF[0]"
identify: unable to open image 'filename:.PDF[0]': No such file or directory @ error/blob.c/OpenBlob/3146.
The only solution I found

Code: Select all

cat 'filename:.PDF' | identify -format '%w %h' -[0]

Re: spaces and annotations in filenames

Posted: 2018-02-21T14:19:37-07:00
by fmw42
On my Mac, if I try to put a colon in a filename, the Mac will object. It says "Try using a name with fewer characters, or with no punctuation marks"

Re: spaces and annotations in filenames

Posted: 2018-02-21T14:33:37-07:00
by Bonzo
I can not see why the OP is adamant on using such bad file names. If the : does not work do not use it; the [0] is to indicate layers or items in an array.

What problems are going to crop up when trying to use the filenames in other software?

What happens if the filename has a : and it needs to be opened in a Windows or mac environment?

How can .pdf[0] be a valid file extension?

I would just say you can not use : or [0] at the end of a filename and call it a day.

Re: spaces and annotations in filenames

Posted: 2018-02-21T16:04:49-07:00
by fmw42
The page id [0], should be fine. I do not see that as a problem. I showed above that by removing the colon and still having spaces and [0] at the end worked fine on my Mac (unix) system. You just have to enclose the whole filename and [0] in double quotes as I showed above.