rochlin has asked for the wisdom of the Perl Monks concerning the following question:

In this thread Chesirecat said he/she had a way of converting 32bit bmp images (from a Windows screen capture) to 24 bit (generally more readable by applications - including image::magick). But he didn't put the code in the reply (and didn't leave an email address so far as I can figure).

Anyone have any code to accomplish that? I don't see how to do it with image::magick - which seems to read in the 32bit bmp files incorrectly.
Thanks

  • Comment on Win32 converting 32bit bmp images to 24bit

Replies are listed 'Best First'.
Re: Win32 converting 32bit bmp images to 24bit
by JaWi (Hermit) on Oct 31, 2002 at 08:56 UTC
    ImageMagick has fairly detailed online documentation for the Perl bindings to their libraries. If you go here, you can see all available options and sample scripts to reach certain effects.

    Untested, and out of the blue I could think of the following script:

    #!/usr/bin/perl -w use strict; use Image::Magick; my($image); $image = new Image::Magick; $image->Read('my_original.bmp'); $image->Quantize(treedepth => 24); open(IMAGE, ">my_output.bmp"); $image->Write(file=>\*IMAGE, filename=>"my_output.bmp"); close(IMAGE);
    Did I already say it isn't tested? :-)

    Success,

    -- JaWi

    "A chicken is an egg's way of producing more eggs."

      That didn't appear to do it. I get an empty file as the output. Just to be clear, I don't think there would be a problem if I had a 24 bit bmp to start with (which is what most applications seem to expect - including image::magick from my tests).

      I do get a warning message on executing any imagemagick method "no magic configuration file found (magic.mgk)-No such file or directory- at test2.pl line" for example. But that doesn't seem to interfere with Image::Magick operation (I ran a couple of the demo.pl scripts from the documentation and they gave the warning but worked fine).

      Probably more to the point is an error I get when reading in the 32 bit bmp in quesetion: "Warning 325: Not a BMP image file (J:/temp/screencaps/newcap.bmp) at imagemagick_test.pl line 7". This image opens fine in Photoshop and in Mozilla 1.1 - so it is a valid BMP. Just (as I said in the original post) a 32bit BMP. Chesirecat said some not so obvious code was needed to get it to 24bit (which then ought to be a valid bmp as far as ImageMagick is concerned). Which brings me back to the original question, which would seem to require some code outside of Image::Magick calls ...

      Test Code: (for ref: line warn after the Read($name))

      use strict; use Image::Magick; my $image = Image::Magick->new; my $name = q(J:/temp/screencaps/newcap.bmp); my $x = $image->Read($name); warn "$x" if "$x"; $x = $image->Write(filename=>'J:/temp/screencaps/new.bmp'); warn "$x" if "$x";