It sounds to me like you are trying to create one large image that contains several smaller ones.

The process to do that should be fairly simple:

  1. Create a large empty GD Image that is big enough to contain all your smaller images. You might want to set the background colour at this point.
  2. Load each image in turn, and paste it into your big image at the correct location.
  3. Save the big image in your prefered file format.

Overall your code might look something like this: (Untested)

use strict; use warnings; use GD; my $outImage = GD::Image->new(1000,1000); # Assume this image is 500x500 pixels my $imageTopLeft = GD::Image->newFromPng('/path/to/file/top/left.png') +; $outImage->copyResized($imageTopLeft, # Src Image; 0,0, # $dstX,$dstY, 0,0, # $srcX,$srcY, 500, 500, # $destW,$destH, 500, 500 ); # $srcW,$srcH, # Assume this image is 200x300 pixels my $imageBottomRight = GD::Image->newFromPng('/path/to/file/bottom/rig +ht.png'); $outImage->copyResized($imageBottomRight, # Src Image; 800,700, # $dstX,$dstY, 0,0, # $srcX,$srcY, 200, 300, # $destW,$destH, 200, 300 ); # $srcW,$srcH, open OUTIMAGE, ">", '/path/to/output/filename.png' or die "Error, unab +le to write output $!"; binmode OUTIMAGE; print OUTIMAGE $outImage->png; close OUTIMAGE;

In reply to Re^3: Merging png by using GD. by chrestomanci
in thread Merging png by using GD. by birdy

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.