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

Does any one know how I can go about converting PNG files to JPEG?

Replies are listed 'Best First'.
Re: Converting PNG to JPEG
by fglock (Vicar) on Aug 22, 2002 at 17:51 UTC
Re: Converting PNG to JPEG
by ChemBoy (Priest) on Aug 22, 2002 at 17:52 UTC

    Use Image::Magick for the conversion. Or of course, just use ImageMagick on the command line (mogrify -format jpeg foo.png).



    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

Re: Converting PNG to JPEG
by cmilfo (Hermit) on Aug 22, 2002 at 17:54 UTC
    Unfortunately, I am not able to test this at the moment. But, this *should* work.
    use Image::Magick; my $rc; my $img = Image::Magick->new(); $rc = $img->Read('file.png'); die "$rc\n" if $rc; $rc = $img->Write('file.jpeg'); die "$rc\n" if $rc;
Re: Converting PNG to JPEG
by simeon2000 (Monk) on Aug 23, 2002 at 03:49 UTC
    As said, definitely go with Image::Magick. I don't believe there are any native perl modules that can deal with PNG or JPEG (after searching CPAN).

    If you're feeling frisky you could try code up the community a tool to read JPEG files natively in perl and write them out to 24-bit bitmap format, and then code up a module to read/write PNG files from bitmaps.

    But since nobody else has done that yet, I don't believe it is trivial. I've written a perl module to deconstruct bitmap files, though. Neat stuff if you get into it.

    --
    perl -e "print qq/just another perl hacker who doesn't grok japh\n/"
    simeon2000|http://holdren.net/

Re: Converting PNG to JPEG
by fruiture (Curate) on Aug 22, 2002 at 17:59 UTC

      That might be a bad idea, though, if your image uses more than 8-bit color--if not, then GD is a great tool.



      If God had meant us to fly, he would *never* have given us the railroads.
          --Michael Flanders

A reply falls below the community's threshold of quality. You may see it by logging in.