Page 1 of 1
bmp2jpg with * wildcard
Posted: 2010-02-23T13:43:42-07:00
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.
Re: bmp2jpg with * wildcard
Posted: 2010-02-23T14:05:35-07:00
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
Re: bmp2jpg with * wildcard
Posted: 2010-02-23T14:38:33-07:00
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
Re: bmp2jpg with * wildcard
Posted: 2010-02-24T01:27:05-07:00
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.
Re: bmp2jpg with * wildcard
Posted: 2010-02-24T03:08:31-07:00
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.
Re: bmp2jpg with * wildcard
Posted: 2010-02-24T10:41:10-07:00
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
Re: bmp2jpg with * wildcard
Posted: 2010-02-24T13:53:09-07:00
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.