Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

batch converting images with image::magick?

by Anonymous Monk
on Aug 27, 2003 at 02:55 UTC ( [id://286935]=perlquestion: print w/replies, xml ) Need Help??

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

i need to batch convert some bitmaps to jpeg format, and since i had image::magick installed already, i wanted to just write a quick script to do it for me, but the documentation for image::magick is frighteningly confusing, so i ask here..how would i open up a bitmap and then write it as a jpeg? help me please....
  • Comment on batch converting images with image::magick?

Replies are listed 'Best First'.
Re: batch converting images with image::magick?
by PodMaster (Abbot) on Aug 27, 2003 at 03:14 UTC
Re: batch converting images with image::magick?
by Zaxo (Archbishop) on Aug 27, 2003 at 03:40 UTC

    Here's an interpreter script that does what you want. The file names are expected from the command line, for instance from a shell glob.

    #!/usr/bin/perl use Image::Magick; for (@ARGV) { my $p = Image::Magick->new(); $p->Read($_); s/\.[^.]+$/.jpeg/; $p->Write($_); }

    After Compline,
    Zaxo

Re: batch converting images with image::magick?
by esh (Pilgrim) on Aug 27, 2003 at 07:12 UTC

    Appropriately, some Perl answers have been provided, but if you don't feel like "just writing a quick script" you could instead "just type a quick command":

    for i in *.bmp; do convert $i `basename $i .bmp`.jpg; done

    I assume you're using Linux/Unix or some OS with command line ImageMagick tools (convert) available.

    -- Eric Hammond

Re: batch converting images with image::magick?
by leriksen (Curate) on Aug 27, 2003 at 08:10 UTC
    We are doing exactly the same type of thing here, using IM to rework some JPEG scans of POW records from WWII, and we found IM to be ... somewhat hackish. The only redeeming feature of IM is that it (somehow) works. However, whenever we get the chance, we use GD - smaller, faster, better documented, easier to install etc etc. I hope saying 'dont use IM' isn't too annoying an answer.
    In this particular case we couldnt use GD becuase we ended up getting an annoying 'moire'-like pattern in the images processed by GD, but a nice smooth background in IM. I think it is a result of the paper we are scanning interacting with the particular algorithms that GD and IM use. This paper is old, being produced in 1930's to 40's. Being paper used for a government contract, it is quite low quality, being very coarse in appearance. You can also make out quite clearly the wire grid paper rested on as it came out the 'wet-end' of the pulp mill, before going through the felt rollers. GD doesn't seem to use any kind of image filtering, so I think the wire grid elements react quite strongly with the small image elements that JPEG uses. IM, by contrast, always puts an image through a filter, by default it is a filter called a Lanczos filter. This results in no patterning, but obviously filtering takes time.
Re: batch converting images with image::magick?
by MrCromeDome (Deacon) on Aug 28, 2003 at 00:17 UTC
    Depending on how many images you plan to be converting, you may wish to look at alternatives. I'll likely get accused of trolling or whatnot for this, but I was very not impressed by the speed of the image compression done by Image::Magick. You may be ok for compressing JPEG images (I didn't try those), but compression of TIFF images was completely not acceptable IMHO. Converting 5-page documents from Group III TIFF to the latest flavor of TIFF took 3-4 seconds each. For my 850,000 image conversion, that would have taken approximately a month of raw processing. Ugh!

    Just a word of warning. ++ to all the excellent suggestions above.

    Cheers!
    MrCromeDome

      I use ImageMagick in Windows and have it also as a stand alone app. Works great.

      Is Gimp-Perl doing similar things, or just utilities for the GIMP?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found