Cannot convert to BMP3 in Windows MSYS2 shell?

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
sdaau
Posts: 10
Joined: 2011-05-23T03:49:56-07:00
Authentication code: 8675308

Cannot convert to BMP3 in Windows MSYS2 shell?

Post by sdaau »

Hi,

The documentation on http://www.imagemagick.org/Usage/formats/#bmp says to use this command, if we want to convert to BMP3:
you can enforce the generation of a BMP3 format image using...

Code: Select all

       convert image BMP3:image.bmp
I have a command like this:

Code: Select all

/d/msys64/mingw64/bin/convert.exe /d/my-project-dir/my_image.xpm BMP3:/d/my-project-dir/my_image.bmp
... which fails with:

Code: Select all

convert.exe: unable to open image 'BMP3;D:\my-project-dir\my_image.bmp': Invalid argument @ error/blob.c/OpenBlob/3490.
The version is:

Code: Select all

$ /d/msys64/mingw64/bin/convert.exe --version
Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-11-06 https://imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo djvu fftw flif fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raw rsvg tiff webp wmf xml zlib
What is the right command syntax that I can use, so that I can convert my .xpm image to BMP3?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cannot convert to BMP3 in Windows MSYS2 shell?

Post by snibgo »

What is your platform? If Windows, why are you using forward slashes between directories?

As you are using IM v7, I suggest you use "magick", not "convert".
snibgo's IM pages: im.snibgo.com
sdaau
Posts: 10
Joined: 2011-05-23T03:49:56-07:00
Authentication code: 8675308

Re: Cannot convert to BMP3 in Windows MSYS2 shell?

Post by sdaau »

Many thanks, @snibgo:
snibgo wrote: 2019-04-11T03:17:13-07:00 What is your platform?
MSYS2 ( https://www.msys2.org/ ) bash shell under Windows 10.

Imagemagick was installed through the `pacman` package manager in MSYS2, using:

Code: Select all

pacman -S mingw-w64-x86_64-imagemagick
snibgo wrote: 2019-04-11T03:17:13-07:00 If Windows, why are you using forward slashes between directories?
Because I'm working in the MSYS2 `bash` shell, which - as it is `bash` - uses forward slashes by default.

I think there is some path handling within MSYS2, so in the end, the programs end up with paths in Windows format regardless (you can notice there are backslashes in the paths noted in the error).

I just want to note that, when I just use this:

Code: Select all

/d/msys64/mingw64/bin/convert.exe /d/my-project-dir/my_image.xpm /d/my-project-dir/my_image.bmp
... the process completes fine, without a problem. The problem only appears when I try to prefix `BMP3:` in front of the output file path.
snibgo wrote: 2019-04-11T03:17:13-07:00 As you are using IM v7, I suggest you use "magick", not "convert".
Thanks, but got same results - without BMP3 prefix it is fine:

Code: Select all

$ /d/msys64/mingw64/bin/magick.exe /d/my-project-dir/my_image.xpm /d/my-project-dir/my_image.bmp
$
... but with BMP3 prefix it fails:

Code: Select all

$ /d/msys64/mingw64/bin/magick.exe /d/my-project-dir/my_image.xpm BMP3:/d/my-project-dir/my_image.bmp
magick.exe: unable to open image 'BMP3;D:\my-project-dir\my_image.bmp': Invalid argument @ error/blob.c/OpenBlob/3490.
Is there any other way to specify BMP3 output format, other than prefixing it to the output file path?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cannot convert to BMP3 in Windows MSYS2 shell?

Post by snibgo »

Yes, bash uses forward slash, that's fine.

Windows has a concept of devices, eg "D:". Bash on Windows doesn't have that concept, so something does a translation. To complicate the situation, IM uses a prefix plus colon to mean a file format.

You command writes to:

Code: Select all

BMP3:/d/my-project-dir/my_image.bmp
... but that gets translated to:

Code: Select all

BMP3;D:\my-project-dir\my_image.bmp
The translation, with semicolon ";" is bad. I suppose the translation is done by MSYS2, which I suppose has a bug.

You might try backslashes, even though bash expects forward slashes. Or use a relative path, avoiding the leading "/d/". Or avoid the leading "BMP3:", piping the output to mogrify which can use "-format BMP3".
snibgo's IM pages: im.snibgo.com
sdaau
Posts: 10
Joined: 2011-05-23T03:49:56-07:00
Authentication code: 8675308

Re: Cannot convert to BMP3 in Windows MSYS2 shell?

Post by sdaau »

Many thanks @snibgo - got it now:
snibgo wrote: 2019-04-11T04:22:11-07:00 The translation, with semicolon ";" is bad. I suppose the translation is done by MSYS2, which I suppose has a bug.

You might try backslashes, even though bash expects forward slashes.
Excellent, that was it: I just tried replacing the original output file path (with forward slashes), with the path written in the error message:

Code: Select all

$ /d/msys64/mingw64/bin/magick.exe /d/my-project-dir/my_image.xpm 'BMP3:D:\my-project-dir\my_image.bmp'
... and it passed without a problem!
snibgo wrote: 2019-04-11T04:22:11-07:00 Or use a relative path, avoiding the leading "/d/". Or avoid the leading "BMP3:", piping the output to mogrify which can use "-format BMP3".
Great to keep this in mind, thanks!
Post Reply