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

Dear Masters,

Is there a way to concatenate several PNG/JPEG images into one single image with Perl?
Image::Magick doesn't seem to be able to do that.

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re: Concatenating Images with Perl
by Fletch (Bishop) on Dec 12, 2007 at 14:59 UTC

    Depends on what you mean by "concatenate", but perhaps you need to read harder. Specifically the Append and Montage methods look promising.

    If those don't fit the bill I think Imager provides an interface geared more towards drawing than manipulating existing images; that might serve.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Concatenating Images with Perl
by moritz (Cardinal) on Dec 12, 2007 at 14:59 UTC
    The docs have an entire section on that topic, saying

    Use method Montage() to create a composite image by combining several separate images. The images are tiled on the composite image with the name of the image optionally appearing just below the individual tile.

Re: Concatenating Images with Perl
by renodino (Curate) on Dec 12, 2007 at 16:11 UTC
    If you mean "tile" images, GD::Tiler may be a smaller/simpler alternative to Image::Magick.

    Perl Contrarian & SQL fanboy
      here's some code from an old program of mine that concatenates two images (image1 and image2.png):
      $tempimage = new Image::Magick; $tempimage->Read('image1.png'); $temppg = new Image::Magick; $temppg->Read('image2.png'); $temppg->Resize(width=>400, height=>351, filter=>Box); $temppg->Border(height=>8, outer=>5, color=>'#FFFFFF'); $temppg->Border(width=>1, height=>1, color=>'#000000'); $comp = new Image::Magick(size=>'710x410'); $comp->Read( 'xc:white' ); #i think this sets the background color $comp->Composite(image=>$tempimage, gravity=>'southeast'); #this dete +rmines where the image will be placed (southeast = bottom right) $comp->Composite(image=>$temppg, gravity=>'southwest'); $comp->Annotate(gravity=>'north', text=>substr($names[$curimage],0,100 +)); #adds a title at the top of the image $comp->Write('concatenated.png');
      hope that helps...
Re: Concatenating Images with Perl
by redhotpenguin (Deacon) on Dec 13, 2007 at 06:23 UTC

    Image::Magick can do what you need. I had to solve a problem where a spammer was sending an image chopped up into equal pieces, each piece attached to the email as an attachment. He used html and inline css to piece the fragments together to display the composite image in the email. I called him 'Mr. Puzzle'.

    I was able to use Image::Magick to put the pieces back together, then another library to OCR the resulting image and run the text through a spam checker. Granted, the API for Image::Magick can be frustrating, but it is pretty fast. Keep at it, you'll get it.

      Er, wouldn't this have been easier?
      $cells = scalar s{(</td>)}{$1}g; $spam += COMPLICATED_TABLE if $cells > 4;

      --
      [ e d @ h a l l e y . c c ]