in reply to Re^2: Merging png by using GD.
in thread Merging png by using GD.

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;

Replies are listed 'Best First'.
Re^4: Merging png by using GD.
by birdy (Initiate) on Apr 06, 2011 at 18:03 UTC
    thank you very much.It really helps me.