Yes, ImageMagick is probably a good idea for this.  I don't know offhand whether it natively supports merging two images, but you could convert the images to XPM, and then perform your own image manipulation on the lines from the XPMs.

Here's an example (from some code I recently wrote) of a subroutine for doing this called convert_image_to_xpm() :

#!/usr/bin/perl -w # # A subroutine for reading jpg and gif images, and converting # them to XPM format # # 060106 liverpole # ############## ### Strict ### ############## use strict; use warnings; ################# ### Libraries ### ################# use File::Basename; use FileHandle; use Image::Magick; ################### ### Subroutines ### ################### sub convert_image_to_xpm($) { my ($fname) = @_; print "=== Converting file $fname to XPM format ===\n"; my $image = new Image::Magick(); my $result = $image->Read($fname); $result and die "Error reading image file '$fname' ($result)\n"; print "Read image '$fname', now writing ...\n"; my $tmp = "convert.$$.xpm"; $result = $image->Write($tmp); $result and die "Error writing .xpm file '$tmp' ($result)\n"; my $fh = new FileHandle(); open($fh, "<$tmp") or die "Cannot read file '$fname' ($!)\n"; chomp (my @lines = <$fh>); close $fh; print "Converted image to .xpm format\n"; unlink $tmp; return \@lines; } #################### ### Main program ### #################### my $iam = basename $0; (my $img = shift) or die " syntax: $iam <image file> Demonstrates usage of the subroutine convert_image_to_xpm, for converting a given .jpg or .gif <image file> to XPM format. "; my $plines = convert_image_to_xpm($img); foreach my $line (@$plines) { print "$line\n"; }
Once it's converted to XPM format, it's very easy to manipulate the image any way you want to.

One other note -- if you're a fan of gvim, when you edit an XPM image, it does something pretty cool:  it renders the actual colors for each pixel in the image.  (Don't try it for images which are too large, though).  This makes it very easy to see how the XPM will display, as well as edit it at the same time.


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"

In reply to Re: merging two .gif or jpg (overlapping) by liverpole
in thread merging two .gif or jpg (overlapping) by Mattk470

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.