You need to create a new image and paste the existing image into it:
my $inim = ...; # some image we want to make square
my $outim = Imager->new(xsize => 400, ysize => 400);
my $ypos = int((400 - 250) / 2);
$outim->box(filled => 1, color => $back_color, ymax => $ypos-1);
$outim->paste(src => $inim, top => $ypos);
$outim->box(filled => 1, color => $back_color, ymin => $ypos + 250);
$outim->write(file => "output.png"); # or whatever you want to do with it
Alternatively, if the source image can be partly transparent, you might want to fill the output image with your background color and use the rubthrough() method:
$outim->box(filled => 1, color => $back_color);
$outimg->rubthrough(src => $inim, tx => $ypos);
|