Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

png to bmp 24

by Anonymous Monk
on Apr 02, 2004 at 22:36 UTC ( [id://342170]=perlquestion: print w/replies, xml ) Need Help??

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

Please help!! I have been working a long time on this and can't get it to work. I have used gd-barcode to convert a number into a png barcode. Then I am using image-magick to convert it to a bmp. I want to use write-excel to open the barcode and print it. I am getting a bmp 8 from image-magick and I need a bmp 24. If I open the bmp 8 in fireworks and convert it to bmp 24 then call it from write-excel it works great. How can I get image-magick or some other perl mod to convert my png file to a bmp 24. Here is my code.
$file="c:/web/bcimages/$ID.png"; $file1="c:/web/bcimages/$ID.bmp"; my($image, $x); $image = Image::Magick->new; $x = $image->Read($file); warn "$x" if "$x"; $x = $image->Write($file1); warn "$x" if "$x";

BazB added code tags.

Replies are listed 'Best First'.
Re: png to bmp 24
by jmcnamara (Monsignor) on Apr 02, 2004 at 23:09 UTC

    ImageMagick comes with a utility called convert. The following usually works for me when I need to convert .png files to the 24 bit .bmp format required by Spreadsheet::WriteExcel:
    convert file.png file.bmp

    --
    John.

Re: png to bmp 24
by nmcfarl (Pilgrim) on Apr 03, 2004 at 00:05 UTC
    Untested but the Image::Magick attribute that controls color depth, is "depth". Since it is per RGB component, a depth of 8 is 24 bit. So a line like
    $image->Set(depth=>8);
    should patch things up. (Hopefully)
Re: png to bmp 24
by Anonymous Monk on Apr 03, 2004 at 00:05 UTC
    Hey thanks, I did notice that but could never get the code right. Can you give me a sample using my code? Thanks a bunch!!
      Sorry to keep bothering you guys but the following two code snipets didnt work for me. It still make a very small files. Do either of you have some working code to help me get out of this mess?
      $file="c:/web/bcimages/$ID.png"; $file1="c:/web/bcimages/$ID.bmp"; my($image, $x); $image = Image::Magick->new; $x = $image->Read($file); warn "$x" if "$x"; $image->Set(depth=>8); $x = $image->Write($file1); warn "$x" if "$x";
      or
      $file="c:/web/bcimages/$ID.png"; $file1="c:/web/bcimages/$ID.bmp"; my($image, $x); $image = Image::Magick->new; $image->Set(depth=>8); $x = $image->Read($file); warn "$x" if "$x"; $x = $image->Write($file1); warn "$x" if "$x";

      jantiored by ybiC: Balanced <code> tags around codeblocks

        Well, working code is the one thing you're not getting from me. This is all from memory (and looking at the docs). I don't have a working ImageMagick install right now, nor the time to get one running.

        Anyhow the first code sample looks like what I would try. It's very odd that it is not working! I'm sure it has worked for me in the past.

        Anyhow I'd definitely try John's suggestion of the command line tools. Then possibly try converting some other pngs, some jpgs. Just start narrowing down the problem. Something has to work. ImageMagick has been very good to me in the past.

        PS. Some 'code' tags would make this much more readable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://342170]
Approved by BazB
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-05-28 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found