bmp2jpg with * wildcard

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
karl3i

bmp2jpg with * wildcard

Post by karl3i »

Hello,

I'm using ImageMagick on Windows 7. I read in the documentation that filename globbing is supported for Unix as well as for Unix.
ImageMagick supports filename globbing for systems, such as Windows, that does not natively support it
So I've tried to convert all BMP files of a folder into JPG using the command:

Code: Select all

"C:\Program Files\ImageMagick-6.5.9-Q16\convert.exe" '%~dp0*.bmp' '%~dp0*.jpg'
I got this error message:
convert.exe: unable to open image `'C:\Users\me\Desktop\bmp2jpg\*.bmp'': Invalid argument @ error/blob.c/OpenBlob/2484.
convert.exe: missing an image filename `'C:\Users\me\Desktop\bmp2jpg\*.jpg' @ error/convert.c/ConvertImageCommand/2919.
Any help would be greatly appreciated!

Thanks,

Karl3i.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: bmp2jpg with * wildcard

Post by el_supremo »

For what you're trying to do you need the mogrify program, not convert.
Be careful that unless you specify otherwise, mogrify overwrites the original image, so test it carefully before letting it loose on a directory full of images. And make a backup anyway.

Pete
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: bmp2jpg with * wildcard

Post by snibgo »

I think IM's globbing is limited to "*" and "?". "%~dp" is a Windows construct for FOR loops. Even if this globbing worked, it wouldn't do what you wanted, as convert can't take a list of filenames and convert each one to a different output. (Well, it could, but with a very complex command.) As Pete says, mogrify would do what you want.

Or you could put the convert inside a Windows for loop:

for %%F in (*.bmp) do "C:\Program Files\ImageMagick-6.5.9-Q16\convert" %%F %%~dpnF.jpg
snibgo's IM pages: im.snibgo.com
karl3i

Re: bmp2jpg with * wildcard

Post by karl3i »

Hello,

thanks for your replies.

Actually "%~dp0" returns the folder where the batch is stored, it was a command dedicated to MS dos, not to convert.exe. I could also have used:

Code: Select all

"C:\Program Files\ImageMagick-6.5.9-Q16\convert.exe" 'C:/path/to/*.bmp' 'C:/path/to/*.jpg'
Moreover, you can see in the output message (unable to open image `'C:\Users\me\Desktop\bmp2jpg\*.bmp'':) that %~dp0 has been properly interprated and replaced by its actual value.

I've read the help here: http://www.imagemagick.org/script/comma ... essing.php (see filename globbing) and I had understood that it could work that way. Did I misunderstand that?

Ok, so I will loop over the command convert, whether with batch or VBS, or take a look at mogrify.

Many thanks for your answers and for your warning regarding possible overwritting.

Regards.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: bmp2jpg with * wildcard

Post by snibgo »

Yes, when used in a batch file, %~dp0 will be translated by the Windows command shell into the directory and path of the batch file. You could then use convert to expand the "*" thus (in a batch file):



convert %~dp0*.bmp %~dp0thing%%03d.jpg



and you will get thing000.jpg, thing001.jpg etc.



But if your output file is *.jpg, convert (version 6.5.8 under Windows) gets tangled up in knots. It seems to make a list of all the output files, and make copies of those.

Under Ubuntu, a similar command (convert *.bmp *.jpg) does the same weird behaviour in 6.4.5.

So does a home-compiled 6.5.9-6.

I wouldn't mind if convert complained about the wildcard destination, but the weird behaviour seems like a bug.
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: bmp2jpg with * wildcard

Post by fmw42 »

IM convert only allows you to generate one output image under most commands. To process a whole directory of files, you need to use mogrify, then you can use *.jpg to process all jpg files in the directory.

I usually create a new directory, say test2, to receive images from test1.

So in unix

cd test1
mogrify -path /Users/fred/test2 -format png *.jpg

will process all jpg images in test1, converting them to png and put them in test2
karl3i

Re: bmp2jpg with * wildcard

Post by karl3i »

Many thanks to all of you.

For my immediate needs, the commandline suggested by Snibgo is just perfect!

Code: Select all

for %%F in (*.bmp) do "C:\Program Files\ImageMagick-6.5.9-Q16\convert" %%F %%~dpnF.jpg
I also keep in mind that I can use mogrify.

Best Regards,

Karl3i.
Post Reply