Convert a 32-bit ARGB BMP to PNG
-
- 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
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
Re: Convert a 32-bit ARGB BMP to PNG
meh, guess I'll have to do that for now.fmw42 wrote:You can change the white to transparent
Re: Convert a 32-bit ARGB BMP to PNG
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.
Re: Convert a 32-bit ARGB BMP to PNG
Well, I already found those, but thanks anyway...fmw42 wrote:see -crop at http://www.imagemagick.org/Usage/crop/#crop
and especially http://www.imagemagick.org/Usage/crop/#crop_equal
- 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
Does that not do what you want? If not, please explain and perhaps we can help further.
Re: Convert a 32-bit ARGB BMP to PNG
No, no, as in, I had already found those myself, and they did what I wanted them to do. Thanks for it anyway.fmw42 wrote:Does that not do what you want? If not, please explain and perhaps we can help further.
Re: Convert a 32-bit ARGB BMP to PNG
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.
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}"