spaces and annotations in filenames

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

spaces and annotations in filenames

Post 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)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: spaces and annotations in filenames

Post 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?
snibgo's IM pages: im.snibgo.com
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

Re: spaces and annotations in filenames

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: spaces and annotations in filenames

Post 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
snibgo's IM pages: im.snibgo.com
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

Re: spaces and annotations in filenames

Post 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.
Last edited by nagame on 2018-02-19T13:21:32-07:00, edited 1 time in total.
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

Re: spaces and annotations in filenames

Post by nagame »

the ":" character is not allowed in Windows file names but allowed in Unix systems like...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spaces and annotations in filenames

Post 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
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

Re: spaces and annotations in filenames

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

Re: spaces and annotations in filenames

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: spaces and annotations in filenames

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

Re: spaces and annotations in filenames

Post 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.
nagame
Posts: 10
Joined: 2018-02-18T16:43:03-07:00
Authentication code: 1152

Re: spaces and annotations in filenames

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

Re: spaces and annotations in filenames

Post 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"
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: spaces and annotations in filenames

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

Re: spaces and annotations in filenames

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