Convert a 32-bit ARGB BMP to PNG

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

Re: Convert a 32-bit ARGB BMP to PNG

Post by snibgo »

I've had success reading V3 ARGB uncompressed files as raw bytes. I've forgotten the syntax, but you tell IM the header size and dimensions, and away it goes.
snibgo's IM pages: im.snibgo.com
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

fmw42 wrote:You can change the white to transparent
meh, guess I'll have to do that for now.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

Actually, an even better solution to this problem would be to simply cut the large image I had into its smaller 16 x 16 tiles, which is what I did this for in the first place. Now that I know ImageMagick exists, I'm trying to find something that will do that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

Well, I already found those, but thanks anyway...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

Does that not do what you want? If not, please explain and perhaps we can help further.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

fmw42 wrote:Does that not do what you want? If not, please explain and perhaps we can help further.
No, no, as in, I had already found those myself, and they did what I wanted them to do. Thanks for it anyway.
mammadori

Re: Convert a 32-bit ARGB BMP to PNG

Post by mammadori »

Since I was caught with a ton of images in this format and since gimp (which handles those alpha bmp format) scripting isn't easy as using imagemagick, I find my way with dd by skipping the header and then treating the image like a raw rgba.

bmp needs to be flipped, I also needed to invert blue with red, so I used a recolor matrix to do that.

It is a bit hackish, but it worked for me.

Code: Select all

#!/bin/sh

MATRIX='0 0 1 0
        0 1 0 0
        1 0 0 0
        0 0 0 1'

IN_IMG="$1"
BASENAME="${IN_IMG%.*}"
RGBAIMG="${BASENAME}.rgba"
OUT_IMG="${BASENAME}.png"
HEADER_SIZE=54

width=$(identify -format "%w" "${IN_IMG}")
height=$(identify -format "%h" "${IN_IMG}")

dd if="${IN_IMG}" of="${RGBAIMG}" bs="${HEADER_SIZE}" skip=1

convert -size ${width}x${height} -depth 8 -flip "${RGBAIMG}" -recolor "${MATRIX}" "${OUT_IMG}"
Post Reply