Unable to pass variable filepath

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?".
Post Reply
Mshepelev
Posts: 1
Joined: 2016-04-22T09:31:52-07:00
Authentication code: 1151
Contact:

Unable to pass variable filepath

Post by Mshepelev »

I'm trying to pass a filepath from a variable as following

Code: Select all

convert -quality 100 -density 500 $FILE[$PAGES] page.jpg
and for some reason if a filename contains spaces im gettings following output:

Code: Select all

convert.im6: unable to open image `/home/mshepelev/Test/NEW\': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `/home/mshepelev/Test/NEW\' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `Cutting\': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `Cutting\' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `Edge\': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `Edge\' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `Upper-Intermediate\': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `Upper-Intermediate\' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `TB.pdf': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `TB.pdf' @ error/constitute.c/ReadImage/544.
convert.im6: no images defined `page.jpg' @ error/convert.c/ConvertImageCommand/3044.
whereas when following command works fine:

Code: Select all

convert /home/mshepelev/Test/NEW\ Cutting\ Edge\ Upper-Intermediate\ TB.pdf test.jpg
it seems like when passing a variable as input filename it is getting splitted by space sign ignoring escape symbols
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:

Re: Unable to pass variable filepath

Post by fmw42 »

try

convert -quality 100 -density 500 "$FILE[$PAGES]" page.jpg

I do not know Windows syntax, but I am not sure that $ is a symbol for a variable in Windows. It is for unix.

See http://www.imagemagick.org/Usage/windows/

Also always provide your IM version and platform, since syntax may differ.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:

Re: Unable to pass variable filepath

Post by snibgo »

@Mshepelev: what platform are you using (Windows, OSX, bash, whatever)? What version of IM?

If your filepaths contain spaces, you should quote them. On Windows, use double quotes ". On bash, I think it is single quotes '.
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
Contact:

Re: Unable to pass variable filepath

Post by fmw42 »

snibgo wrote:@Mshepelev: what platform are you using (Windows, OSX, bash, whatever)? What version of IM?

If your filepaths contain spaces, you should quote them. On Windows, use double quotes ". On bash, I think it is single quotes '.
He is using Windows as far as I can tell, but using unix variable syntax.

On unix, you need to double quote variables or they will not be resolved by single quotes.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 21 guests