http://qs1969.pair.com?node_id=362080

#code to convert 32bit BMP (actually DIB) to 24bit sub check_bmp { $input = shift; $output = shift; open(INPUT,"<$input"); binmode(INPUT); # now read in the header read(INPUT,$buff,54); # sig, filesize, reserved, dataoffset, size, width, height, planes, +bitcount, compression, imagesize # xpixelsM, ypixelsM , colorsused, colorsimportant ( $sig, $filesize, $reserved, $dataoffset, $size, $width, $height, $ +planes, $bitcount, $compression, $imagesize, $xpixelsM, $ypixelsM , $colorsused, $colorsimportant ) + = unpack($headertemplate,$buff); if ($bitcount != 32) { close(INPUT); rename($input,$output); } else # only rework if 32 bit { # print "\n\tProcessing $input to $output\n"; open(OUTPUT,">$output"); binmode(OUTPUT); $bitcount = 24; $compression = 0; $imagesize = int (($imagesize) * 0.75); $filesize = $imagesize + $dataoffset; @fields = ( $sig, $filesize, $reserved, $dataoffset, $size, $width +, $height, $planes, $bitcount, $compression, $imagesize, $xpixelsM, $ypixelsM , $colorsused, $colorsimportant + ); $buff2 = pack($headertemplate,@fields); syswrite(OUTPUT,$buff2,54); $count = 0; # now rewrite the BMP, dropping the alpha channel until( eof(INPUT) ) { read(INPUT, $pixel, 4); ($r, $g, $b, $a) = unpack($rgbapixeltemplate,$pixel); $rgbpixel = pack($rgbpixeltemplate, $r, $g, $b); # $rgbpixel = $r.$g.$b; syswrite(OUTPUT,$rgbpixel,3); } close(INPUT); close(OUTPUT); # remove the .dib file unlink($input); } }